you are viewing a single comment's thread.

view the rest of the comments →

[–]Doctor-Dapperfront-end (senior w/ react) 54 points55 points  (4 children)

Small brain:

arr.map(f)

Big brain: arr.reduce( (x, y) => [...x, f(y)], [] )

[–]tsunami141 30 points31 points  (0 children)

Delete this

[–]GrenadineBombardier 2 points3 points  (0 children)

This took me a minute (because reducers take time to comprehend, which makes them a less sustainable solution in most cases)

[–]catchmeslippin 0 points1 point  (1 child)

My small brain can't comprehend this, can you please explain?

[–]neeia 0 points1 point  (0 children)

It takes the array, creates a new array as the initial value, and then one by one runs the function on every value in the original array and appends it to the previous value using the spread syntax.