Created
February 7, 2017 19:05
-
-
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
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 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