Skip to content

Instantly share code, notes, and snippets.

@JasonDeving
Created May 1, 2016 05:37
Show Gist options
  • Save JasonDeving/ac9e6cfca80ee4a8e7e4fcac00e9a30e to your computer and use it in GitHub Desktop.
Save JasonDeving/ac9e6cfca80ee4a8e7e4fcac00e9a30e to your computer and use it in GitHub Desktop.
FInd the max number with es6 with an array.
let numbers = [4,6,3,8];
let max = Math.max(...numbers);
console.log(max);
@otaviomedeiros
Copy link

👍

@i7an
Copy link

i7an commented Jun 9, 2017

[1,2,3,4].reduce((max, n) => n > max ? n : max)

@cmdcolin
Copy link

Note that for a moderately large array, Math.max(...numbers) can blow the call stack size and give "Maximum call stack size exceeded" errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment