@extra-array/partition
Version:
Segregates values by test result.
50 lines (36 loc) • 1.38 kB
Markdown
Segregates values by test result.
[:package:](https://www.npmjs.com/package/@extra-array/partition)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/partition)
[:vhs:](https://asciinema.org/a/332102)
[:moon:](https://www.npmjs.com/package/@extra-array/partition.min)
[:scroll:](https://unpkg.com/@extra-array/partition/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [partition], [partitionAs].<br>
> Similar: [count], [partition].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.partition(x, ft);
// x: an array
// ft: test function (v, i, x)
// → [satisfies, doesnt]
```
```javascript
const array = require("extra-array");
var x = [1, 2, 3, 4];
array.partition(x, v => v % 2 == 0);
// [ [ 2, 4 ], [ 1, 3 ] ]
var x = [1, 2, 3, 4, 5];
array.partition(x, v => v % 2 == 1);
// [ [ 1, 3, 5 ], [ 2, 4 ] ]
```
<br>
<br>
## References
- [Data.List.partition: Haskell](http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:partition)
[partition]: https://github.com/nodef/extra-array/wiki/partition
[partitionAs]: https://github.com/nodef/extra-array/wiki/partitionAs
[count]: https://github.com/nodef/extra-array/wiki/count