function myflat(array) {
let newArr = [];
function fn(arr) {
arr.forEach(item => {
if (Array.isArray(item)) {
fn(item)
} else {
newArr.push(item)
}
})
return newArr
}
return fn(array)
}
let arr = [1, 2, {},
[4, 5, [6, [7]]]
]
console.log(myflat(arr));