In the grammar checker project in the beginner javasctipt course, there is some additional improvements you can do for extra practice.
one says " Changing the imperial units of measurement (feet and miles) to metric units (meters and kilometers). "
does anyone know how to get the numbers out of an array of strings?
this is what I have so far:
let story = ‘56 Last weekend, I took literally the most beautifull bike ride of my life. The route is called “The 9W to Nyack” and it 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 literally took me an entire day. I stopped at Riverbank State Park to take some artsy photos. It was a short stop, though, because I had a freaking long way 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 a breathtaking 4,760 feet long! I was already very tired by the time I got to the other side. An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautifull park along the coast of the Hudson. Something that was very surprising to me was that near the end of the route you literally cross back into New York! At this point, you are very close to the very end.’;
let storyWords = story.split(’ ');
let unnecessaryWord = ‘literally’;
let misspelledWord = ‘beautifull’;
let badWord = ‘freaking’;
//console.log(storyWords);
let count = 0;
storyWords.forEach(word => {
return count++
})
//console.log(count)
storyWords = storyWords.filter(word => {
return word !==unnecessaryWord;
})
storyWords = storyWords.map((word) => {
return word === misspelledWord ? ‘beautiful’ : word;
});
let badWordIndex = storyWords.findIndex((word) => {
return word === badWord
});
//console.log(badWordIndex);
storyWords[78] = ‘really’;
let lengthCheck = storyWords.every((word) => {
return word >= 10
});
//console.log(lengthCheck)
let toLongIndex = storyWords.filter((word) =>{
return word.length > 10
});
//console.log(toLongIndex)
let changeWord =storyWords.findIndex((word) => {
return word === ‘breathtaking’
});
//console.log(changeWord)
storyWords[111] = ‘glorious’
for (let i = 0; i < storyWords.length; i++){
if (storyWords[i] === ‘very’){
storyWords.splice(i,1);
} else {
storyWords[i];
}
};
for (let i = 0; i < storyWords.length; i++){
if (storyWords[i] === ‘GW’){
storyWords.splice(i,1, ‘George Washington’);
} else {
storyWords[i];
}
};
for(let i = 0; i<storyWords.length; i++){
if (typeof storyWords[i] === ‘number’ && storyWords[i+1] === ‘feet’){
storyWords[i] /= 3.28;
storyWords[i+1] = ‘meters’;
} else if (typeof storyWords[i] === ‘number’ && storyWords[i+1] === ‘miles’){
storyWords[i] *= 1.609;
soryWords[i+1] = ‘kilometers’;
} else {
storyWords[i]
}
};
console.log(storyWords.join(’ '));
but the issue was pulling the numbers out of an array of strings.
Ive found ways to do it, but none that seem to belong in a beginner course.
anyone have input on how they did or would do it?
Or input on the way the way you would think the lesson would have you do it with the knowledge that one would posses in the beginner course?