Functional Programming - Use the map Method to Extract Data from an Array

Tell us what’s happening:
I was trying to write my solution similar to solution 1 with regular function instead of arrow function, but did not get the right result. The result that returned is an array of objects that contain only the title key pairs. I guess it failed because the return statement stopped once it found the key pairs. I can’t figure out how to get the right result with regular function. My question is: Is it possible to replace the arrow function in solution 1 with a regular function at all? If yes, how?

//provided solution 1

const ratings = watchList.map(item => ({
title: item[“Title”],
rating: item[“imdbRating”]
}));

//my solution
const ratings = watchList.map(function(element){
return {“title”:element[“Title”],“rating”:element[“imbdRatings”]};
})
//return  [{“title”:“Inception”},{“title”:“Interstellar”},{“title”:“The Dark Knight”},{“title”:“Batman Begins”},{“title”:“Avatar”}]

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36

Challenge: Functional Programming - Use the map Method to Extract Data from an Array

Link to the challenge:

Hey there,

do I see typo here?

Was that it or is there another problem?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.