Last active
March 29, 2016 21:15
-
-
Save Kallin/779861020915dddf8d020b2523276a8c to your computer and use it in GitHub Desktop.
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
def find_descendants(person) | |
descendants = [] | |
children = person[:children] | |
if children | |
descendants << children | |
children.each do |child| | |
descendants << find_descendants(child) | |
end | |
end | |
return descendants | |
end | |
person = { | |
name: 'Leo', | |
children: [ | |
{name: 'Harvey', children: [ | |
{name: 'Kallin'}, | |
{name: 'Seth'} | |
]}, | |
{name: 'Paul', children: [ | |
{name: 'Mark'}, | |
{name: 'Alan'} | |
]}, | |
] | |
} | |
puts find_descendants(person) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment