Horrible nested array:
x=[0,[1,[2,[3,[4,["five"],[5]]]],["to",["free",["floor"]]],["two",["three",["four"]]]]]
Output of the magic function that I would like:
magic(x)=>[[0,1,2,3,4,"five"],[0,1,2,3,4,5],[0,1,"to","free","floor"],[0,1,"two","three","four"]]
So far with:
magic(x)==>
this.unpack_gret = function(strut){
var lenstruc = strut.length;
var firstelem = strut.shift();
if (lenstruc > 1){
var maprecur = strut.map(function(item){
var retrecur = [firstelem].concat(this.unpack_gret(item))
return retrecur
});
if (maprecur.length > 1){return maprecur}
else {return maprecur[0];}
}
else {
return [firstelem];
};
};
I get:
[0,[1,2,3,[4,"five"],[4,5]],[1,"to","free","floor"],[1,"two","three","four"]]
Not bad but not there either. Any ideas?
0?