9 ms·
Probably the same person who thought [1, 2, 3, 4].reduce((x, y) => Math.min(x, y)) should be 1 but [1, 2, 3, 4].reduce(Math.min) should be NaN, for
by Silhouette 8y ago
Probably the same person who thought
[1, 2, 3, 4].reduce((x, y) => Math.min(x, y))
should be 1 but
[1, 2, 3, 4].reduce(Math.min)
should be NaN, for similar reasons. Unfortunately it's a recurring theme in JS that a lot of useful functions have optional extra parameters and a lot of useful higher order functions pass extra context to their callbacks, causing many traps for the unwary if you try to use these tools in a style that works fine in most functional programming languages.