'Flatten array using recursion
I have to flatten an array using recursion, but I am not able to understand, why this code is always outputting an empty array. Can someone please help me here. This is the code
function flatten(arr){
let result = [];
function helper(arr) {
for(let i = 0; i<arr.length; i++){
if(Array.isArray(arr[i])){
helper(arr[i]);
return result;
}else{
result.push(arr[i]);
}
}
}
return result;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
