I have a hierarchically nested associative array. It looks like this:
A = {
B = {
C = {},
D = {},
},
E = {
F = {
G = {}
}
},
H = {}
}
I would like to write a function that returns the "ancestors" of each key.
So:
f("A") = {"A"}
f("B") = {"B","A"}
f("C") = {"C","B","A"}
f("G") = {"G","F","E","A"}
f("fake") = {}
I've worked out I need to use recursion, but I'm having difficulty writing the function. Could someone give me some pointers on how to write such a function?
(Please don't refer me to http://xkcd.com/138/!)