Basically while answering one of the question on SO related to nested array flattening i have answered question with using recursive flattening.
var exampleArray = [ [1,2,3,4], [1,2,[1,2,3]], [1,2,3,4,5,[1,2,3,4,[1,2,3,4]]] ];
function findArrayLengths(input) {
return input.reduce((op,cur)=>{
return Array.isArray(cur) ? op.concat(findArrayLengths(cur)) : op.concat(cur)
},[])
}
let op = exampleArray.map(e=>{
return findArrayLengths(e).length
})
console.log(op);
But i have seen this code also seems to work fine ( flat with infinite depth) i have read a bit about Array.prototype.Flat
var arr = [ [1,2,3,4], [1,2,[1,2,3]], [1,2,3,4,5,[1,2,3,4,[1,2,3,4]]], [[1,2,3,4], [1,2,[1,2,3]], [1,2,3,4,5,[1,2,3,4,[1,2,3,4]]]] ];
let op = arr.map(e=> e.flat(Infinity).length);
console.log(op);
So the question is. is it a proper way to do deep flattening with flat like this or there are consequences. ?
Here's a link to that question and you can check up more here https://stackoverflow.com/a/53844891/9624435