Last active
June 12, 2018 22:18
-
-
Save zwacky/bc46e5906a623bb78086a83d6652babd 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
// the 3 line reduce callback | |
[{key: 'USA', value: […]}, {key: 'Germany', value: […]}, {key: null, value: []}] | |
.filter(item => item.key) | |
.map(item => { | |
item.key = item.key.toUpperCase(); | |
return item; | |
}) | |
.reduce((accumulator, item) => { | |
accumulator[item.key] = item.value; | |
return accumulator; | |
}, {}); | |
// could turn into | |
[{key: 'USA', value: […]}, {key: 'Germany', value: […]}, {key: null, value: []}] | |
.filter(item => item.key) | |
.map(item => (item.key = item.key.toLowerCase(), item)) | |
.reduce((accumulator, item) => (accumulator[item.key] = item.value, accumulator), {}); | |
// -> {USA: […], GERMANY: […]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment