Deep flattens an array.
Array.prototype.concat()
with an empty array ([]
) and the spread operator (...
) to flatten an array.const deepFlatten = arr =>
[].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
deepFlatten([1, [2], [[3], 4], 5]); // [1, 2, 3, 4, 5]
JavaScript, Array
Flattens an array up to the specified depth.
JavaScript, Array
Generates all permutations of an array's elements (contains duplicates).
JavaScript, Array
Create a n-dimensional array with given value.