Last active
September 6, 2016 07:14
-
-
Save tuarrep/4c1bc6dfcd9bf6fc35a9b24163617490 to your computer and use it in GitHub Desktop.
Déméler les valeurs nutritionnelles !
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 keys = Object.keys(nutriments); | |
let parsed = {}; | |
const primitives = keys | |
.filter((key) => key.split('_').length == 1); | |
primitives.forEach((key) => { | |
let secondaries = keys.filter((secondKey) => { | |
let splitted = secondKey.split('_'); | |
return splitted.length == 2 && splitted[0] == key; | |
}).map((filteredKey) => { | |
return filteredKey.split('_')[1]; | |
}); | |
let result = {}; | |
secondaries.forEach((secondary) => { | |
result[secondary] = nutriments[`${key}_${secondary}`]; | |
}) | |
parsed[key] = result; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment