You’re welcome. As mentioned earlier, I like to come back to this module and play around from time to time, though it only happens when somebody brings it up. So thank you for bringing it up.
At some point in the exercise we may be asked, 'How many sentences are there in the story?"
function splitOnFullStop (text) {
var fullStops = ":.?!".split("");
fullStops.forEach(s => {
text = text.split(s).join('\n');
});
return text.split('\n ');
}
sentences = splitOnFullStop(story);
console.log(sentences.length);
sentences.forEach(x => console.log(x));
The return line splits the string into an array, but we could send back the string and split it later. The newlines are embedded and there is no more full stop punctuation. The string will print out the same as the array returned above, though it would be harder to get the count. Trade-offs all around.
This process could be front-of-line since it operates on the story
text immediately, not something intermediate. As a string it would be simple to implement our earlier process of stripping non-word characters, and we now have less to strip. The only one’s left are the semi-colon, the comma, and the double quote.
In this demonstration (meant to tell you earlier) we left the single quote to allow for contractions. it's
and its
are two different things entirely, for example. Don’t want to mess things up too much.
function embedNewlines (text) {
var fullStops = ":.?!".split("");
fullStops.forEach(s => {
text = text.split(s).join('\n');
});
return text;
}
embedNewlines(story)
=> 'Last weekend, I took literally the most beautiful bike ride of my life\n The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey\n It\'s really an adventure from beginning to end\n It is a 48 mile loop and it basically took me an entire day\n I stopped at Riverbank State Park to take some extremely artsy photos\n It was a short stop, though, because I had a really long way left to go\n After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey\n The GW is actually very long - 4,760 feet\n I was already very tired by the time I got to the other side\n An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson\n Something that was very surprising to me was that near the end of the route you actually cross back into New York\n At this point, you are very close to the end / finish\n'
console.log(embedNewlines(story));
Last weekend, I took literally the most beautiful bike ride of my life
The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey
It's really an adventure from beginning to end
It is a 48 mile loop and it basically took me an entire day
I stopped at Riverbank State Park to take some extremely artsy photos
It was a short stop, though, because I had a really long way left to go
After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey
The GW is actually very long - 4,760 feet
I was already very tired by the time I got to the other side
An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson
Something that was very surprising to me was that near the end of the route you actually cross back into New York
At this point, you are very close to the end / finish
When we inserted the newline substitute the space after the full stop still remained. We dealt with that in the array example. That space may still need to be dealt with when splitting this string, but I would ignore it since all that gets produced is an empty string in one element of the resultant array.
Seems our recent frequency table turned up thrree empty strings, as I recall.
Couldn’t let it go…
text = text.split(`${s} `).join('\n');
Last weekend, I took literally the most beautiful bike ride of my life
The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey
It's really an adventure from beginning to end
It is a 48 mile loop and it basically took me an entire day
I stopped at Riverbank State Park to take some extremely artsy photos
It was a short stop, though, because I had a really long way left to go
After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey
The GW is actually very long - 4,760 feet
I was already very tired by the time I got to the other side
An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson
Something that was very surprising to me was that near the end of the route you actually cross back into New York
At this point, you are very close to the end / finish.
All this is so we can restore the case on words retained in the linting process. With these original sentences in tow we should be able to accomplish it. The actual full stop is not preserved so a period will have to suffice when we resolve this. However, we do have the original story. It could be useful to restore all the full stops.