Reduce - Functional JavaScript - Supercharged

preview_player
Показать описание
In this mini series, Surma introduces you to the various functional methods that JavaScript Arrays have to offer. In this episode: The infamous and feared reduce()!

Рекомендации по теме
Комментарии
Автор

I think you should have touched on the additional argument that can be used to provide an initial value.
It can be very useful if the reduction should be of another type, so you provide the "neutral" state of that type.
You may also need it to get the correct behavior if empty arrays are a case to consider.

ELStalky
Автор

Does reduce return a new or mutated object/array?: const state = {a: 1, b: 2} [3, 4].reduce((accumulator, value) => {change state}, state). I've found Reduce super helpful when using AllIds(arrays) and ById(Objects) to manage state and objects themselves. Used in combination, it's clean and easy to reason however I never dedicated the time to truly test if it mutates. So I'd always just {...state}

boomer
Автор

I think everybody understands the Fibonacci's sequence with .reduce(), what would be really valuable is seeing others examples of usage.

lour
Автор

Nice function. I know just where i will use this.

TheHermitHacker
Автор

Yeah right aptly named in Javascript. Reduce is aptly named in Common Lisp which JS took. So no credit to JS

Nikku
Автор

Hi Surma, perfect video as always. How will you do async reduce?

ZiX
Автор

On the thumbnail there is info from the movie about some and every (js func) and the movie is about reduce ;-/

krzusiekniwazne
Автор

Great video, could you do one on .sort() ?? I console.log the values, but I'm still not sure how the sort function works in JS.

maddenjunkie
Автор

I always thought the last argument was mandatory.

omri