- Notifications
You must be signed in to change notification settings - Fork4
A proposal to make filtering arrays easier
License
tc39/proposal-array-filtering
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A proposal to addArray.prototype.filterReject.
constarray=[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];
- Justin Ridgewell (@jridgewell)
CurrentStage: 1
Array.p.filter is confusing. I constantly have to ask myself "am Ikeeping, or filtering out the current item?".
- "Keeping"
Implies that returning
truewould keep the current item.- "Filtering out"
Implies that returning
truewould 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 towrite an array filter, I end up writing the opposite of what I intended.
Array.p.filterReject attempts to fix this confusion. By providing aclearly named filtering function that matches my intuition, I'm ablewhat will happen when callingfilterReject. And because it exists, I'mable to assume thatfilter does something different, so it must be"keep" version.
A polyfill is available in thecore-js library. You can find it in theECMAScript proposals section.
- Supporting Data from HTTP Archive and GitHub Archive
- What should
filterOutbe called? - Should
partitionbe included?
- Ruby
- Underscore
_.select(aliased to _.filter)_.reject_.partition
- Lodash
About
A proposal to make filtering arrays easier
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.