Skip to content

Instantly share code, notes, and snippets.

@tuarrep
Last active September 6, 2016 07:14
Show Gist options
  • Save tuarrep/4c1bc6dfcd9bf6fc35a9b24163617490 to your computer and use it in GitHub Desktop.
Save tuarrep/4c1bc6dfcd9bf6fc35a9b24163617490 to your computer and use it in GitHub Desktop.
Déméler les valeurs nutritionnelles !
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