Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tc39/proposal-array-filtering
A proposal to make filtering arrays easier
https://github.com/tc39/proposal-array-filtering
Last synced: about 2 months ago
JSON representation
A proposal to make filtering arrays easier
- Host: GitHub
- URL: https://github.com/tc39/proposal-array-filtering
- Owner: tc39
- License: mit
- Created: 2019-10-24T02:19:41.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-20T00:34:17.000Z (about 3 years ago)
- Last Synced: 2024-06-04T15:42:13.654Z (4 months ago)
- Language: HTML
- Homepage: https://tc39.es/proposal-array-filtering/
- Size: 73.2 KB
- Stars: 173
- Watchers: 15
- Forks: 5
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# proposal-array-filtering
A proposal to add `Array.prototype.filterReject`.
```js
const array = [1, 2, 3, 4, 5];// filter keeps the items that return true.
array.filter(i => (i < 3)); // => [1, 2];// filterReject removes the items that return true.
array.filterReject(i => (i < 3)); // => [3, 4, 5];
```## Champions
- Justin Ridgewell ([@jridgewell](https://github.com/jridgewell/))
## Status
Current [Stage](https://tc39.es/process-document/): 1
## Motivation
`Array.p.filter` is confusing. I constantly have to ask myself "am I
keeping, or filtering out the current item?".
- "Keeping"
-
Implies that returning `true` would keep the current item.
- "Filtering out"
-
Implies that returning `true` would remove the current item.
`Array.p.filter` acts as "keeping". But when I think of the word
"filter", I think of "filtering out". So every time that I attempt to
write an array filter, I end up writing the opposite of what I intended.
`Array.p.filterReject` attempts to fix this confusion. By providing a
clearly named filtering function that matches my intuition, I'm able
what will happen when calling `filterReject`. And because it exists, I'm
able to assume that `filter` does something different, so it must be
"keep" version.
## Polyfill
A polyfill is available in the [core-js](https://github.com/zloirock/core-js) library. You can find it in the [ECMAScript proposals section](https://github.com/zloirock/core-js#array-filtering).
## Ongoing Discussions
- [Supporting Data from HTTP Archive and GitHub Archive](https://github.com/jridgewell/proposal-array-filtering/issues/4)
- [What should `filterOut` be called?](https://github.com/jridgewell/proposal-array-filtering/issues/6)
- [Should `partition` be included?](https://github.com/jridgewell/proposal-array-filtering/issues/2)
## Related
- Ruby
- [`Array#select`](https://ruby-doc.org/core-2.4.1/Array.html#method-i-select)
- [`Array#reject`](https://ruby-doc.org/core-2.4.1/Array.html#method-i-reject)
- [`Array#partition`](https://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-partition)
- Underscore
- [`_.select`](https://underscorejs.org/#filter) (aliased to _.filter)
- [`_.reject`](https://underscorejs.org/#reject)
- [`_.partition`](https://underscorejs.org/#partition)
- Lodash
- [`_.reject`](https://lodash.com/docs/4.17.15#reject) ([700k downloads/week](https://www.npmjs.com/package/lodash.reject))
- [`_.partition`](https://lodash.com/docs/4.17.15#partition) ([18k downloads/week](https://www.npmjs.com/package/lodash.partition))