Nice alternative! That is the way I used to do this before the spread operator. Works just as well.
You might want to safeguard this with Number.NEGATIVE_INFINITY as the initial value in reduce in case of an empty array. Math.max() also returns -Infinity when called without any parameters.
Nice alternative! That is the way I used to do this before the spread operator. Works just as well.
You might want to safeguard this with Number.NEGATIVE_INFINITY as the initial value in
reduce
in case of an empty array.Math.max()
also returns-Infinity
when called without any parameters.That'd surely be worth doing, I really only added that code to give an example close to the code that was quoted.
Fair enough. 👍