-
-
Save anonymous/a6f6a57c3dc47d365e38 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
@data={ "p4" => { | |
'parent_id' => "p1" | |
'id' => "p10" | |
}, | |
"p2" => { | |
'parent_id' =>"p1" | |
'id'=>"p20" | |
}, | |
"p11" =>{ | |
'parent_id'=>"p20" | |
'id' =>"p111" | |
}, | |
"p22" =>{ | |
'parent_id'=>"p2" | |
'id'=>"p123" | |
} | |
} |
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 child_nodes(root_node="p1") | |
@data.select { |k,v| v.parent_id == root_node } | |
end | |
def flatten_childen(id,node_depth=1) | |
if node_depth == 0 | |
#return something? | |
else | |
#decrease depth?? | |
child_nodes(id).merge(child_nodes(id).map { |a,b| b.id }.each { |a| child_nodes(a) }) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment