What is the principle behind this?
newArr.some(Array.isArray)
=== newArr.some(elem => Array.isArray(elem))
How is posible that they are parsed as equal?
I thought that newArr.some(Array.isArray)
=== newArr.some(Array.isArray())
(assuming that some
is a loop and that JS assumed each val as the implicit arg of the func), but it's not. So, I'm confused. Please, help me.
Here, there are 2 applications of the cases above:
function flatMultiArr(arr) {
let newArr = [].concat(...arr);
return newArr.some(Array.isArray)
? flatMultiArr(newArr)
: newArr
}
console.log();//[ 1, {}, 3, 4 ]
function flatMultiArr(arr) {
let newArr = [].concat(...arr);
return newArr.some(elem => Array.isArray(elem))
? flatMultiArr(newArr)
: newArr
}
console.log();//[ 1, {}, 3, 4 ]
Note this question is not about how to flatten multidimentional arrays.