Skip to content

Instantly share code, notes, and snippets.

@RoseCrime
Created May 20, 2018 16:08
Show Gist options
  • Save RoseCrime/ffa9a2a72acb6b1247116ca1157d0590 to your computer and use it in GitHub Desktop.
Save RoseCrime/ffa9a2a72acb6b1247116ca1157d0590 to your computer and use it in GitHub Desktop.
reduce method
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