Skip to content

Instantly share code, notes, and snippets.

@keyserfaty
Created February 7, 2017 19:05
Show Gist options
  • Save keyserfaty/c8834915a2476035b867ac89ded067dd to your computer and use it in GitHub Desktop.
Save keyserfaty/c8834915a2476035b867ac89ded067dd to your computer and use it in GitHub Desktop.
A recursive fn over an array and then the props of an object
const buildObject = actions => {
const buildObjectRecursive = (actions, result) => {
for (let key in actions) {
if (actions[key].activity !== 'branch') {
result[actions[key].name] = {
...actions[key]
};
}
for (let k in actions[key]) {
if (Array.isArray(actions[key][k])) {
buildObjectRecursive(actions[key][k], result);
}
}
}
return result;
};
return buildObjectRecursive(actions, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment