Answers for "js deep flatten array"

0

js deep flatten array

var deepFlatten = function (array){
  return array.reduce(function(r, e) {
    return Array.isArray(e) ? r.push(...deepFlatten(e)) : r.push(e), r
  }, [])
};

console.log(deepFlatten([]))     
console.log(deepFlatten([1, 2, 3]))
console.log(deepFlatten([[1, 2, 3], ["a", "b", "c"], [1, 2, 3]]))
console.log(deepFlatten([[[3], [4], [5]], [9], [9], [8], [[1, 2, 3]]]))
Posted by: Guest on September-25-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language