We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Flatten nested lists to given depth.
Alternatives: flat, flatMap.
function flat(x, n, fm, ft) // x: nested lists // n: maximum depth [-1 ⇒ all] // fm: map function (v, k, x) // ft: test function for flatten (v, k, x) [is]
const xlists = require('extra-lists'); var x = [['ab', 'cde'], [ [['a', 'b'], [1, 2]], [['c', 'de'], [ 3, [['d', 'e'], [ 3, [['e'], [ 5 ]] ]] ]] ]]; xlists.flat(x).map(c => [...c]); // → [ [ 'a', 'b', 'c', 'd', 'e' ], [ 1, 2, 3, 3, 5 ] ] xlists.flat(x, 1).map(c => [...c]); // → [ [ 'a', 'b', 'c', 'de' ], [ 1, 2, 3, [ [Array], [Array] ] ] ] xlists.flat(x, 2).map(c => [...c]); // → [ [ 'a', 'b', 'c', 'd', 'e' ], [ 1, 2, 3, 3, [ [Array], [Array] ] ] ]