DEV Community

Discussion on: Code Snippets: Array.prototype.reduce()

Collapse
 
konrud profile image
Konstantin Rouda

I believe for finding Max Number example
it might be easier, and perhaps more readable, to use Math.max()


const numbers = [1, 2, 3, 4, 5];

const max = Math.max(...[1, 2, 3, 4, 5]); 
// 5

Enter fullscreen mode Exit fullscreen mode
Collapse
 
esdev profile image
Ethan Smith

Absolutely, the max numbers example in this article is only to show basic usage and syntax of the reduce method with a very simple use case. Using Math.max would likely be a better option for finding the maximum in most real programming scenarios.