I have an array of strings like this, each string is separated by comma. They can be in any order. I would like to build a nested hash out of it. If an item already exists, then subsequent elements should be nested. Example:
["a", "a,b", "d", "d,e", "d,e,f", "a,b,foobar"]
I want the output to be -
{
a => {
b => foobar
},
d => {
e => f
}
}
I was thinking to iterate over each element, then split it on , and add to a temporary Hash in some recursive way, but I can't figure out how to get them nested.
fcome from in the result? Is there supposed to be a"d,e,f"in the input, perhaps?"a"=>{"b"=>"foobar"}.