| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Flatten nested array to given depth.
function flat(x, n, fm, ft)
// x: a nested array
// n: maximum depth [-1 ⇒ all]
// fm: map function (v, i, x)
// ft: flatten test function (v, i, x) [is]const xarray = require('extra-array');
var x = [[1, 2], [3, [4, [5]]]];
xarray.flat(x);
// → [ 1, 2, 3, 4, 5 ]
xarray.flat(x, 1);
// → [ 1, 2, 3, [ 4, [ 5 ] ] ]
xarray.flat(x, 2);
// → [ 1, 2, 3, 4, [ 5 ] ]| Back | FazBrowse Home | New Git URL |