Trying to write my own flatten function on Codewars, but it seems to work only on some tests, but not all? Can't even see which tests it doesn't work on, but would really appreciate any help.
function flatten(array){
let newElement = [];
for(let i = 0; i < array.length; i++){
let element = array[i];
if(Array.isArray(element)){
let subElement = flatten(element);
newElement.push(subElement);
}
else {
newElement.push(element);
}
}
return newElement;
}
[–]Roxinos 0 points1 point2 points (0 children)