The code above is the solution presented on fCC for the challenge in the topic’s title.
Why are the curly braces followed by “return” and another set of curly braces necessary in the callback function both in the .map, as in .filter? Why not the below?
As a note, it’s generally a best practice to filter first when chaining methods. It means that overall you are doing fewer computations when you filter first.
I think I understand that the syntax is just backward when using an arrow function, but anything you have to add would be appreciated. Thanks for replying.
The property name always goes on the left. When creating an object, the value to assign to that property for the object goes on the right. When destructuring an object, the variable to bind to the value of that property goes on the right. (i.e. the variable you want to save the value of the property into)
Respectfully, I believe title: in the challenge is the alias we are giving the value from movie[‘Title’], and we could make it anything we wish. I’m sorry but it still seems backwards to me.
I think your understanding of this line is backwards. This line is making new objects, not destructuring old objects.
The .map() method takes a function as the argument. The input of this function is the original entries of the array that is being mapped. The output is the new array entries.
In this case, we are taking each movie from the old array and making a new object that only has a title and rating.
So the callback function for the map is equivalent to
I went back and have been doing every single “Basic Data Structures” assignment using arrow functions and callback functions. I definitely have a gap in my knowledge that needs to be closed.
I think that’s a good way to practice. My first real programming was in C, so it took me lots of practice to get used to fancy stuff like arrow functions and high order methods.