@extra-array/filter
Version:
Keeps values which pass a test.
65 lines (51 loc) • 2.48 kB
Markdown
Keeps values which pass a test.
[:package:](https://www.npmjs.com/package/@extra-array/filter)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/filter)
[:vhs:](https://asciinema.org/a/332046)
[:moon:](https://www.npmjs.com/package/@extra-array/filter.min)
[:scroll:](https://unpkg.com/@extra-array/filter/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [filter], [filter$], [filterAt].<br>
> Similar: [map], [filter], [reject], [reduce], [accumulate].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.filter(x, ft);
// x: an array
// ft: test function (v, i, x)
```
```javascript
const array = require("extra-array");
var x = [1, 2, 3, 4, 5];
array.filter(x, v => v % 2 === 1);
// [ 1, 3, 5 ]
array.filter(x, v => v % 2 === 0);
// [ 2, 4 ]
```
<br>
<br>
## References
- [Data.List.filter: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:filter)
- [Array.prototype.filter: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
- [array_filter: PHP](https://www.php.net/manual/en/function.array-filter.php)
- [_.remove: lodash](https://lodash.com/docs/4.17.15#remove)
- [_.without: lodash](https://lodash.com/docs/4.17.15#without)
- [_.compact: lodash](https://lodash.com/docs/4.17.15#compact)
- [_.pull: lodash](https://lodash.com/docs/4.17.15#pull)
- [_.pullAll: lodash](https://lodash.com/docs/4.17.15#pullAll)
- [_.pullAllBy: lodash](https://lodash.com/docs/4.17.15#pullAllBy)
- [_.pullAllWith: lodash](https://lodash.com/docs/4.17.15#pullAllWith)
- [Array.filter: sugarjs](https://sugarjs.com/docs/#/Array/filter)
- [Array.exclude: sugarjs](https://sugarjs.com/docs/#/Array/exclude)
- [Array.compact: sugarjs](https://sugarjs.com/docs/#/Array/compact)
- [array-tools.where: @75lb](https://www.npmjs.com/package/array-tools)
[filter]: https://github.com/nodef/extra-array/wiki/filter
[filter$]: https://github.com/nodef/extra-array/wiki/filter$
[map]: https://github.com/nodef/extra-array/wiki/map
[reduce]: https://github.com/nodef/extra-array/wiki/reduce
[accumulate]: https://github.com/nodef/extra-array/wiki/accumulate
[filterAt]: https://github.com/nodef/extra-array/wiki/filterAt
[reject]: https://github.com/nodef/extra-array/wiki/reject