Created
May 1, 2016 05:37
-
-
Save JasonDeving/ac9e6cfca80ee4a8e7e4fcac00e9a30e to your computer and use it in GitHub Desktop.
FInd the max number with es6 with an array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers = [4,6,3,8]; | |
let max = Math.max(...numbers); | |
console.log(max); |
[1,2,3,4].reduce((max, n) => n > max ? n : max)
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
👍