GitHub - tc39/proposal-array-filtering: A proposal to make filtering arrays easier | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

tc39/proposal-array-filtering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proposal-array-filtering

A proposal to add Array.prototype.filterReject.

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

Status

Current Stage: 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 library. You can find it in the ECMAScript proposals section.

Ongoing Discussions

Related

About

A proposal to make filtering arrays easier

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.