Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A proposal to make filtering arrays easier

License

NotificationsYou must be signed in to change notification settings

tc39/proposal-array-filtering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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];

Champions

Status

CurrentStage: 1

Motivation

Array.p.filter is confusing. I constantly have to ask myself "am Ikeeping, or filtering out the current item?".

"Keeping"

Implies that returningtrue would keep the current item.

"Filtering out"

Implies that returningtrue 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 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.

Polyfill

A polyfill is available in thecore-js library. You can find it in theECMAScript proposals section.

Ongoing Discussions

Related


[8]ページ先頭

©2009-2025 Movatter.jp