Mini Linter Project Help


#1

Hello,

I am struggling with Iterations ‘Mini Linter Project’. I am trying to use the filter method as suggest but do not seem to be doing it correctly. I have look at the documentation and I must not be understanding it when being used to filter out text. I have no problem filtering text based on length values or numerical values.

What I need is help understanding this better. I have tried using the include method as well but don’t think I am setting this up right. Here is my current code and help would be appreciated.

Basically I need to remove the unnecessaryWords from the new storyWords I created with the split method.

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

let overusedWords = ['really', 'very', 'basically'];

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

let storyWords = story.split(' ');

let betterWords = storyWords.filter(function(unnecessaryWords){
  return storyWords.includes(unnecessaryWords);
});

console.log(storyWords.length);

I also tried this but that failed to produce the desired results

let betterWords = storyWords.filter(function(word){
  return storyWords - word.includes(unnecessaryWords);
});

Thanks again in advance. Extra thanks if you can point me to additional material to understand these better. Docs are usually ok but today my brain just is mush.


#2

Please remember to include a link to the exercise when posting questions in Q&A. Thanks. Also include any error messages from the SCT or the console.

Found > https://www.codecademy.com/courses/learn-javascript-iterators/projects/mini-linter?course_redirect=introduction-to-javascript


#3

Hello,

Sorry about that

Here is the link:
Mini Linter Project

I’m actually not getting any errors, just not getting the results I should when I log it to console to check the length of the new array. Currently the storyWords array length is 188. If I iterate through the array and filter our the unnecessary words it should return the new array (betterWords) minus those three words which would be 185. But I either get 188 again or 0. My forehead is in danger of developing an impression of my keyboard lol.

This is my latest attempt which produced undefined

let betterWords = storyWords.includes(function(extras){
  return extras.filter(unnecessaryWords);
});

this one produces 0 for betterWords length

let betterWords = storyWords.filter(function(extras){
  return extras.includes(unnecessaryWords);
});

Thanks again


#4

The SCT will accept ES6 arrow syntax:

let betterWords = storyWords.filter(word => ... );

Now let’s consider how filter works. We give it a condition to satisfy and it returns an array of only accepted terms in the original array.

Here are some ideas:
1.For the overused words, remove it every other time it appears.
2.Write a function that finds the word that appears the greatest number of times.
3 Replaced overused words with something else.

We want to know that the overusedWords array does not contain the current word, and if so return it.

! overusedWords.includes(word)

So this would give us…

let betterWords = storyWords.filter(word => ! overusedWords.includes(word));

#5

Thank you, that helps a lot. I’m still getting used to the ES6 syntax. I’ve been trying to refactor to it. I can see what I did wrong now. It looks like 1) I had the parameter/arrays in the wrong spots and 2) I wasn’t checking to see if unnecessaryWords array did not include the words from the storyWords array.

This is what I got after reading your post and reverse engineering it from ES6

let betterWords = storyWords.filter(function(word){
  return !unnecessaryWords.includes(word);
});

This is what I ended up using in my code:

let betterWords = storyWords.filter(word => ! unnecessaryWords.includes(word));

Thanks again that helped me better understand both filter and includes methods.

edited copied old code


#6

sorry but I have tried to copy and paste on the project with your code and it comes out the error message. Is is working though or I missed sth?


#7
const arr = 'abcdefghijklmnopqrstuvwxyz'.split('');
const vow = 'aeiou';
let a = arr.filter(char => ! vow.includes(char));
console.log(a.toString());
// => b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z

#9

That is very a very helpful explanation of filter. I was also stuck on this part of the project and in about the same place as byterockstar. I was missing the understanding of the ‘!’ or ‘does not’ syntax. Thanks @mtf !


#10

Thanks for this, it helps a lot! I’m always so close to getting the Javascript right… but it just hasn’t quite clicked with me yet.


#12