re: Find the largest number in an Array - one line VIEW POST

TOP OF THREAD FULL DISCUSSION
re: console.time('first') Math.max(...array) console.timeEnd('first') // first: 0.179ms console.time('second') array.reduce((acc, val) => v...
 

Depends what the codes for really.

Math.max() is easier to read, and if only run occasionally on small arrays... fine.

Reduce is a little more convoluted, but still can be understood easily enough. The time savings on the code if running frequently or on larger datasets can quickly add up in benefits.

code of conduct - report abuse