Created
October 27, 2019 08:11
-
-
Save allucardster/54b2c9db5d2632e7b5516e81ef67e285 to your computer and use it in GitHub Desktop.
Create a colors config object from a `object[]` and `selected[string]` values
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
const colors = [ | |
{ | |
"color": "black", | |
"total": 99 | |
}, | |
{ | |
"color": "brown", | |
"total": 93 | |
}, | |
{ | |
"color": "white", | |
"total": 66 | |
} | |
]; | |
const selected = ['brown']; | |
const config = Object.fromEntries(Array.from( | |
colors.map(result => result.color), | |
color => [color, selected.indexOf(color) >= 0] | |
)); | |
console.log(config); | |
// expected: Object { black: false, brown: true, white: false } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment