Skip to content

Instantly share code, notes, and snippets.

@ladas-larry
Last active August 13, 2017 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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