Stumped on the last little bit of "Use the filter Method to Extract Data from an Array"

Edit: I removed the Number() from the first function just playing around and now it passes all the tests. I guess I’m even more confused now. Why would a string pass the >=8 test?

For anyone not familiar, the goal of this is to return the array of new objects which pass a test. Here is my code:

let mappedList = watchList.map(obj => ({title: obj["Title"], rating: Number(obj["imdbRating"])   }));
console.log(mappedList); 
let filteredList = mappedList.filter( obj => obj.rating >= 8);

The console.log() shows what I expected just fine. filteredList in shows what I want in the console, but did not pass the final test. After forever trying to figure out why, I think I’ve learned that my code is returning objects whose keys are not in strings. (For example, their expect code shows "title": "Inception" whereas mine shows title: "Inception". Small difference.

So first I guess I’d like to ask if this is in fact the reason I’m not passing the test.

Also, I just can’t figure out how to get keys and values back into strings without messing everything up.

Thanks in advance for any help!

Okay, on phone so can’t look at this in detail but two things immediately:

Why would a string pass the >=8 test

It says the value should be >= 8. So it should be a number >= 8. If It is not, JS will not blow up at this point, it will attempt to turn (coerce) the value into a number so it can make the comparison. If it can’t, only then it will blow up.

No, all object keys are strings, those two things are exactly the same (JS allows you to miss off the quotes around the keys if you want – if it didn’t, JS would be incredibly painful to write)

2 Likes

Wow. That was a far more concise and legible explanation than I expected, thank you! I think I full understand what happened and why now, I very much appreciate you taking the time on your phone :slight_smile:

1 Like