Tell us what’s happening:
Not sure why (based on lesson example) solution is not …
const ratings = watchList.map(item => [item.Title, item.Rated]);
With output…
[ [ 'Inception', 'PG-13' ],
[ 'Interstellar', 'PG-13' ],
[ 'The Dark Knight', 'PG-13' ],
[ 'Batman Begins', 'PG-13' ],
[ 'Avatar', 'PG-13' ] ]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Challenge: Functional Programming - Use the map Method to Extract Data from an Array
Link to the challenge:
You have created an array of arrays, but you must have an array of objects
Waiting: ratings should equal [{“title”: “Inception”, “rating”: “8.8”}, {“title”: “Interstellar”, “rating”: “8.6”}, {“title”: “The Dark Knight”, “rating”: “9.0”},{“title”: “Batman Begins”, “rating”: “8.3”}, {“title”: “Avatar”, “rating”: “7.9”}]
I agree…however…the example doesn’t cover making an array of Objects…did I miss something?
As the challenges progress, the instructions stop providing examples you can directly copy.
In this case, you need to use knowledge from previous challenges. How do you create an object? I mean in general. What is the syntax for making a new object?
Agreed…must have been covered in the earlier JS exercises. First time through so I probably just didn’t retain that. Lol.
const ratings = watchList.map(item => ({title: item.Title, rating: item.imdbRating}));
There you go.
This one is a bit tricky because of the combination of arrow function implicit returns and object {}s
Actually…the only coverage of Arrow notation are the two links listed below. Not sure this is enough to do the exercise.
Write Arrow Functions with Parameters
Use Arrow Functions to Write Concise Anonymous Functions
You don’t need to use an arrow function. People like to use arrow functions with functional methods, but a traditional function works fine here too.
Sorry…not sure I see how to do that. If you had an example…that would be great. I understand the “arrow notation” method. Just don’t see how it can be done without.
An arrow function is mostly just different syntax, so you can swap around to other syntax for functions:
const ratings = watchList.map(function (item) {
return {title: item.Title, rating: item.imdbRating};
}
);
This is the part of the curriculum where there are many ways to do one task
1 Like
Nice…Much appreciated. I will assume that Arrow notation is the way to go now with ES6. Helps (me) to know what things were like before arrow notation to understand why they moved to the new syntax.
Thanks for your help!
1 Like
system
Closed
February 1, 2023, 2:40am
12
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.