So, in the " Use the map Method to Extract Data from an Array" lesson we’re supposed to transform that for loop in a map method that will return the same thing.
So I did this:
const ratings = watchList.map(film => {
return {title: film["Title"], ratings: film["imdbRating"]}
});
but the lesson would not complete. So I look at the exercise resolution, which is:
const ratings2 = watchList.map(film => ({
title: film["Title"], ratings: film["imdbRating"]
}));
I called the exercise resolution “ratings 2” so that I can compare both returns, and printed both variable results to the console:
console.log(JSON.stringify(ratings));
console.log("---")
console.log(JSON.stringify(ratings2));
[{"title":"Inception","ratings":"8.8"},{"title":"Interstellar","ratings":"8.6"},{"title":"The Dark Knight","ratings":"9.0"},{"title":"Batman Begins","ratings":"8.3"},{"title":"Avatar","ratings":"7.9"}]
---
[{"title":"Inception","ratings":"8.8"},{"title":"Interstellar","ratings":"8.6"},{"title":"The Dark Knight","ratings":"9.0"},{"title":"Batman Begins","ratings":"8.3"},{"title":"Avatar","ratings":"7.9"}]
It seems to me that both resolutions are returning exactly the same. So I wonder why my code didn’t work and the resolution did, could somebody point it out for me?
Thanks in advance!