Last active
August 13, 2017 09:58
-
-
Save ladas-larry/73595c22cd8d65d33850588aa8e2c07c to your computer and use it in GitHub Desktop.
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
//array of objects to array of values | |
var arr = [{val: 'foo'}, {val: 'bar'}]; | |
arr = arr.map((item) => { | |
return item.val; | |
}); | |
console.log(arr) // ['foo', 'bar'] | |
// reversing string | |
var str = 'abcde' | |
str = str.split('').reverse().join(''); | |
console.log(str) // 'edcba' | |
//using map/reduce | |
const programmerOutput = [ | |
{ | |
name: 'Uncle Bobby', | |
linesOfCode: 500 | |
}, { | |
name: 'Suzie Q', | |
linesOfCode: 1500 | |
} | |
]; | |
const INITIAL_VALUE = 0; | |
const totalOutput = programmerOutput | |
.map((programmer) => programmer.linesOfCode) | |
.reduce((acc, linesOfCode) => acc + linesOfCode, INITIAL_VALUE); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment