3 ms·
I think your giving a bad map reduce example. It is written in a very immature functional programming style. It should be written like this, IMO: var r = ar
by RubenSandwich 9y ago
I think your giving a bad map reduce example. It is written in a very immature functional programming style.
It should be written like this, IMO:
var r = array
.map(square)
.reduce(sum, 0);
Differences:
1. Separating out actions by line
2. Pass named functions that describe what they do
- jasonkostempski 9y agoEliminating the map, named functions or not, makes it pretty clear: var r = array.reduce((total, num) => total + (num * num), 0);