Created
May 20, 2018 16:08
-
-
Save RoseCrime/ffa9a2a72acb6b1247116ca1157d0590 to your computer and use it in GitHub Desktop.
reduce method
This file contains hidden or 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 vals = [1, 3, 65, 7, 3, 2, 6, 75, 3, 42, 12, 312, 23] | |
let sum = vals.reduce((storage, val) => storage + val) | |
console.log(sum); | |
let biggest = vals.reduce((storage, val) => val > storage ? val : storage), | |
lowest = vals.reduce((storage, val) => val > storage ? storage : val) | |
console.log(biggest); | |
console.log(lowest); | |
/*let biggest = vals.reduce((storage,val)=>{ | |
if(val>storage){ | |
storage=val | |
} | |
return storage | |
})*/ | |
//same thing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment