@extra-array/flat-map
Version:
Flattens nested array, based on map function.
51 lines (36 loc) • 1.39 kB
Markdown
Flattens nested array, based on map function.
[:package:](https://www.npmjs.com/package/@extra-array/flat-map)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/flat-map)
[:vhs:](https://asciinema.org/a/332052)
[:moon:](https://www.npmjs.com/package/@extra-array/flat-map.min)
[:scroll:](https://unpkg.com/@extra-array/flat-map/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [flat], [flatMap].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```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 ]
```
<br>
<br>
## References
- [Array.prototype.flatMap: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
- [_.flatten: lodash](https://lodash.com/docs/#flatten)
[flat]: https://github.com/nodef/extra-array/wiki/flat
[flatMap]: https://github.com/nodef/extra-array/wiki/flatMap