I am encountering an issue with a specific function that I have
const flat = function(arr, n) {
if (n == 0) {
return arr;
} else if (n == 1) {
let newarr = []
for (let i = 0; i < arr.length; i++) {
if (Number.isInteger(arr[i])) {
newarr.push(arr[i])
} else if (Array.isArray(arr[i])) {
newarr.concat(arr[i]) //look here
}
}
return newarr
}
};
console.log(flat([2,4,[2,4,9],1,6],1))
that is, when the function is called with these values
([2,4,[2,4,9],1,6],1)
The expected output should be
2,4,2,4,9,1,6
however, the actual output is
2,4,1,6
This means that the array inside another array is not being included in the final result