Flattens nested array, based on map function.
npm install @extra-array/flat-mapFlattens nested array, based on map function.
:package:
:smiley_cat:
:running:
:vhs:
:moon:
:scroll:
:newspaper:
:blue_book:
> Alternatives: [flat], [flatMap].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
``javascript`
array.flatMap(x, [fm], [ft]);
// x: an array
// fm: map function (v, i, x)
// ft: test function (v, i, x)
`javascript
const array = require("extra-array");
var x = [[1, 2], [3, [4, [5]]]];
array.flatMap(x);
// [ 1, 2, 3, [ 4, [ 5 ] ] ]
array.flatMap(x, v => array.flat(v, 1));
// [ 1, 2, 3, 4, [ 5 ] ]
array.flatMap(x, v => array.flat(v));
// [ 1, 2, 3, 4, 5 ]
``
- Array.prototype.flatMap: MDN web docs
- _.flatten: lodash
[flat]: https://github.com/nodef/extra-array/wiki/flat
[flatMap]: https://github.com/nodef/extra-array/wiki/flatMap