Tell us what’s happening:
i can’t see where did i make a mistake.
Actually it’s should work because i’m getting expected values
[1, {}, [3, [[4]]]] returned -> [1, {}, 3, 4]
Your code so far
var re=[];
function test1(arr){
if(Array.isArray(arr) & arr.length > 1 ){
test2(arr);
}else if(Array.isArray(arr[0])){
test1(arr[0]);
}else{
if(arr[0] != null )re.push(arr[0]);
}
}
function test2(arr){
for(var i=0;i<arr.length;++i){
if(Array.isArray(arr[i])){
test1(arr[i]);
}else{
if(arr[i] != null )re.push(arr[i]);
}
}
}
function steamrollArray(arr) {
// I'm a steamroller, baby
for(var i=0;i<arr.length;++i){
if(Array.isArray(arr[i])){
test1(arr[i]);
}else{
if(arr[0] != null )re.push(arr[i]);
}
}
arr=re;
return arr;
}
steamrollArray( [1, {}, [3, [[4]]]] );
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0.
Link to the challenge:
https://www.freecodecamp.org/challenges/steamroller

