Functional Programming: Use the filter Method to Extract Data from an Array //Question seems to confuse itself

so this question ask us to Use a combination of filter and map to return a new array to there spec, easy enough now it adds this curve ball:

Note that the rating values are saved as strings in the object and you may want to convert them into numbers to perform mathematical operations on them.

ok so i did the first part

filteredList = watchList
.filter( (rating) => (rating["imdbRating"] >= 8.0))
.map( (value) => ({"title":value["Title"],"rating":value["imdbRating"]}))

and checked the object in the browser console and it worked so i pressed go next to see if it was ok as javascript converts stuff when it can by itself it didnt pass i spent 20minutes thinking ok how the hell to i go into the object to though the keys and edit on of the values and then i saw i had a caps on the Title, changed it to a lower case and it did pass LOL!
i checked soulation afterwards like i always do and the soulation didnt have any converting of string to int either so first off i think is that there just to confuse us? second off how would i go about doing such a task
would it be something along the lines of a for in loop using hasOwnProp === rating and then converting it with number() or parseFloat()?

Nothing you find on FCC is there “just to confuse you”. In this case, implicit casting is working in your favor and you don’t need to explicitly cast the string as a number.

Can be as simple as doing this inside your filter callback. Can use Number() as well, you are right. As far as the solution in FCC guides not doing conversions it’s wrong and it’s a bad practice…

Imagine a situation where you have to compare two ratings, for example if you want to sort the items in your watchlist by rating. When comparing two strings without converting them to numbers JS exhibits this behaviour:

"2" > "12" //true

You can read more about string comparison here

1 Like