Created
March 6, 2019 21:12
-
-
Save tjeastmond/e61776a563964b9607d1c1102651ad57 to your computer and use it in GitHub Desktop.
Because I couldn't not do it...
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
function getNames(person) { | |
const names = []; | |
names.push(person.name); | |
person.children.forEach(child => names.push(...getNames(child))); | |
return names; | |
} | |
const people = { | |
name: "Robin", | |
children: [ | |
{ | |
name: "Alberto", | |
children: [ | |
{ | |
name: "Quinn", | |
children: [ | |
{ | |
name: "Conner", | |
children: [] | |
}, | |
{ | |
name: "Lila", | |
children: [] | |
} | |
] | |
} | |
] | |
}, | |
{ | |
name: "Charlie", | |
children: [] | |
} | |
] | |
}; | |
console.log("getNames(people): ", getNames(people)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment