javascript - Word Filter using array methods -
let story = 'last weekend, took literally beautiful bike ride of life. route called "the 9w nyack" , stretches way riverside park in manhattan south nyack, new jersey. it\'s adventure beginning end! 48 mile loop , took me entire day. stopped @ riverbank state park take extremely artsy photos. short stop, though, because had long way left go. after quick photo op @ popular little red lighthouse, began trek across george washington bridge new jersey. gw long - 4,760 feet! tired time got other side. hour later, reached greenbrook nature sanctuary, extremely beautiful park along coast of hudson. surprising me near end of route cross new york! @ point, close end.'; let overusedwords = ['really', 'very', 'basically']; let unnecessarywords = ['extremely', 'literally', 'actually' ]; let storywords = story.split(' '); console.log(storywords.length); let betterwords = storywords.includes(unnecessarywords);
so there's javascript code above.
this class assignment. we're learning iterators arrays. (basically methods defined here: https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/array)
what i've done set string story. made 2 different arrays, 1 overused words , 1 unnecessary words.
then made array take string variable story saved each word , put new array called storywords.
now i'm trying create array removes unnecessary words. want iterate on array filter out these words , save remaining words in array called betterwords.
how can this? told not use loops , take advantage of iterators learned. i'm sure there's sort of function have accomplish can't life of me figure out.
right i'm thinking need use either .filter or .includes i'm not sure how go it.
use array#filter array#include inside , reverse result.
let story = `last weekend, took literally beautiful bike ride of life. route called "the 9w nyack" , stretches way riverside park in manhattan south nyack, new jersey. it\'s adventure beginning end! 48 mile loop , took me entire day. stopped @ riverbank state park take extremely artsy photos. short stop, though, because had long way left go. after quick photo op @ popular little red lighthouse, began trek across george washington bridge new jersey. gw long - 4,760 feet! tired time got other side. hour later, reached greenbrook nature sanctuary, extremely beautiful park along coast of hudson. surprising me near end of route cross new york! @ point, close end.`; let unnecessarywords = ['extremely', 'literally', 'actually' ]; let storywords = story.split(' '); let betterwords = storywords.filter(sw => !unnecessarywords.includes(sw.tolowercase())); console.log(betterwords);
Comments
Post a Comment