I've been working on flattening an array, but I noticed that my code stopped processing when it encountered a nested Array. The output I'm getting is [ 1, 2, 3, [ [ [Object] ] ] ]
.
Could someone explain to me why the code isn't continuing through the nested Arrays and why it's failing to concatenate properly? Thank you!
flatten = function(nestedArray, result) {
result = [];
each(nestedArray, function(item){
if(Array.isArray(item)){
result = result.concat(item);
} else {
result.push(item);
}
});
return result;
};
flatten([1, [2], [3, [[[4]]]])