I am working through creating a flatten function on my own and I came up with this:
function flatten(newArr, result = []) {
for (let x = 0; x < newArr.length; x++) {
if (Array.isArray(newArr[x])) {
flatten(newArr[x], result)
} else {
result.push(newArr[x])
}
}
return result
}
Are there any pitfalls here that I am missing? I assume the big O would be O(n) since this is a linear loop that depends on the numb