Skip to content

Instantly share code, notes, and snippets.

@ladas-larry
Last active August 13, 2017 09:58
Show Gist options
  • Save ladas-larry/73595c22cd8d65d33850588aa8e2c07c to your computer and use it in GitHub Desktop.
Save ladas-larry/73595c22cd8d65d33850588aa8e2c07c to your computer and use it in GitHub Desktop.
//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