Functional Programming: Use the map Method to Extract Data from an Array - Breakdown (can someone check? :P)

Functional Programming: Use the map Method to Extract Data from an Array - Breakdown (can someone check? :P)
0

#1

Finally made it past this challenge but it took me forever to figure this out XD The Get a hint solution gave a solution that worked but in the small piece of code there was a lot going on. To help other beginners I made a breakdown of the code and used color coding to explain each bit. Could someone take a look at this and see if the explanation is accurate?

Note: Forum posts do not support color coding. The breakdown can be viewed in google docs:


#2

Basically, this is a pretty accurate breakdown. Two things jump out at me, though:

  1. Note that in #6, you’re not only creating a new object, you’re implicitly returning that new object. By having some sort of value as the only thing following a fat arrow function, it’s shorthand for return that one value (whether a string, a number, an array, or an object).

  2. Your item["title"] is interchangeable with item.title in this case. You aren’t passing "title" and "imdbRating" as variable data, so it isn’t strictly necessary here. Not saying you’re wrong, you’re truly not. but in this case, either would represent the same data.

But yep, that’s a pretty clear summation, and I like that approach to note-taking.


#3

This was really helpful, thank you! I understand arrow functions when I read them, but I’m not yet able to spontaneously create them yet… I still have to write a regular functions and then progress from there. It makes sense that you have to wrap the new object in parentheses to differentiate it from a function.

Thanks again!


#4

Thanks for checking! item.name looks more familiar as well. I hope you don’t mind, I’ve added your notes to the breakdown. :slight_smile: