Last active
June 1, 2017 04:13
-
-
Save bryzettler/f8a97f6845513b5b9e83430d9bced757 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
const records = [ | |
{ title: "The Clash", artist: "The Clash", type: "LP", lengthSec: 2220, released: "1977"}, | |
{ title: "Rocket to Russia", artist: "Ramones", type: "LP", lengthSec: 1906, released: "1977"}, | |
...etc | |
]; | |
// es5 | |
const way = records.reduce((acc, record) => { | |
acc[`${record.title} - ${record.artist}`] = record; | |
return acc; | |
}, {}); | |
// es6 | |
const way = records.reduce((acc, record) => ({ | |
...acc, | |
[`${record.title} - ${record.artist}`]: record, | |
}), {}); | |
/* | |
=> { | |
"The Clash - The Clash": { artist: "The Clash", lengthSec: 2220, released: "1977", title: "The Clash", type: "LP"}, | |
"Rocket to Russia - Ramones": { artist: "Ramones", lengthSec: 1906, realease: "1977", title: "Rocket to Russia", type: "LP"}, | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment