DEV Community

Discussion on: 🔥 Getting the largest number from an array

Collapse
 
domhabersack profile image
Dom Habersack

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.

Thread Thread
 
oliverradini profile image
OliverRadini

That'd surely be worth doing, I really only added that code to give an example close to the code that was quoted.

Thread Thread
 
domhabersack profile image
Dom Habersack

Fair enough. 👍