Assume I have an unknown string array such as:
arr = [fruit/bananas:10, fruit/apples/0:5, fruit/apples/1:8, fruit/apples/2:7, car/honda/civic:1];
and I want to populate an object such that each array value is a path to its object value (ie arr becomes obj below):
obj = {
'fruits' :{
'bananas' : 10,
'apples' : [5,8,7]
},
'car' :{
'honda':{
'civic': 1
}
}
};
I am just wondering what type of recursive function would be best since the actual array length for each value is unknown so just splitting '/' and populating wouldn't work (that I could figure out)