Intermediate Algorithm Scripting ,Steamroller problem is solved with map but does not work

Intermediate Algorithm Scripting ,Steamroller problem is solved with map but does not work
0

#1
var str=[];
function steamrollArray(arr) {
 
 
 arr.map(function(a){
 			if(Array.isArray(a)){
      	str=steamrollArray(a);
      }else{
      	str.push(a);
      }
 });
 
 return str;
}


steamrollArray([1, [2], [3, [[4]]]]);

Can someone help me understand why this answer is wrong?


#2

Solutions that use global variables generally don’t work in the challenges. You’ll have to rewrite your code so that there are no globals.


#3

Opps! I did not know that! Thank you! :slight_smile: