Skip to content

Instantly share code, notes, and snippets.

@casprwang
Created February 14, 2017 06:28
Show Gist options
  • Save casprwang/a76a7c139ecb7fb511f49caa510ec013 to your computer and use it in GitHub Desktop.
Save casprwang/a76a7c139ecb7fb511f49caa510ec013 to your computer and use it in GitHub Desktop.
// two way to shorten an array
let s = '123456'
// reduce
// list => single num/string
let sum = [1, 2, 3, 4, 5].reduce((a, b) => a + b)
// list => a single num
let biggest = [...s].reduce((a, b) => Math.max(a, b))
// filter
// array => shorter array
let biggerThan3 = [...s].filter((val) => val > 3) //return a array
console.log(sum)
console.log(biggest)
console.log(biggerThan3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment