markdown guide

Array.prototype.reduce() seems to be much faster.

array.reduce((acc, val) => val > acc ? val : acc);
console.timeEnd('first') // first: 0.179ms

    array.reduce((acc, val) => val > acc ? val : acc)
console.timeEnd('second') // second: 0.054ms

Definitively slower to execute but half the time to write it :)


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.

Classic DEV Post from Jan 29

The 7 Myths of Learning to Code

Learning to code products doesn't take as long as you think - more precisely, 300 hours to learn, build, and launch. Learn about the history and misconceptions of development preventing you from even starting and then hop on that tech bus.

Drozerah profile image
Software Developer actually interested in JavaScript Back-End