Mini Linter Project #4: Iterators

First time asking a question. I am doing the Mini Linter project and cant seem to get past #4.

I need to compare two arrays and count the number of times each word from the secondary array appears in the primary. I wanted to use Iterators, but i cant make it work:

let 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.';

const storyWords = story.split(' ')

let unnecessaryWords = ['extremely', 'literally', 'actually' ];

 const unnecessaryArr = storyWords.filter (storyWord => {
  return storyWord.includes(unnecessaryWords)

Why does this not filter all the words into one array so I can log the length?

Thank you so much!!

1 Like

The key is in this section here. Think about what it is you’re doing here, more specifically the types of each element. storyWord is your element for the iterator, so this is going to be a single element from the array storyWords. Therefore when you are using storyWord.includes, what exactly is this iterating on?

Thank you! I got it to work

 const unnecessaryArr = storyWords.filter (storyWord => {
  return unnecessaryWords.includes(storyWord)