Need help with Use the filter the Method to Extract Data from an Array problem

Hi so so far for the problem I have this code written out;

var filteredList = watchList.filter(imdbRating => 8.0);

I got the first three checkmarks accept for the last one so I must be on the right track, but im a little stuck. I dont know what to do from here at this point so that I can get the result I would like. Please help.

This isn’t the right way to write a callback function, but I can see where you are getting confused.

// Your => doesn't do what you might think
//                                             ↓This is not a greater than or equal too
var filteredList = watchList.filter(imdbRating => 8.0);

Your callback function for your filter needs to check if the current item in the watch list has an imdbRating that’s at least 8.0, but right now your callback function just returns the number 8.0;


Here is how arrow functions work:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

And here is how filter works:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter


It would help others if you include a link to the challenge in your top post so they can help better :slight_smile:

2 Likes

Filter iterates through an, and on each element it will call the callback and if the return value of that is true then that element gets added to the array that filter will return after it has iterated through your entire array. Currently you are returning a number in your callback and that number is then being turned into a boolean which is causing your filter to allow everything into the new array as the only number that gets coerced into false is the number 0. You are going to want your callback to return a bool value per each element which can be done as such [1,0,1,2].filter(e => e > 0) a comparison is a bool value and that filter would return [1,1,2] as the 1th index element was not greater than 0.