Created
February 14, 2017 06:28
-
-
Save casprwang/a76a7c139ecb7fb511f49caa510ec013 to your computer and use it in GitHub Desktop.
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
// 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