Skip to content

Instantly share code, notes, and snippets.

@evolutionxbox
Last active April 12, 2017 12:28
Show Gist options
  • Save evolutionxbox/cc09662c0597276bf6a32a11c0698732 to your computer and use it in GitHub Desktop.
Save evolutionxbox/cc09662c0597276bf6a32a11c0698732 to your computer and use it in GitHub Desktop.
Like filter, but negated
/*
# `Array.prototype.reject`
## Summary
Like `filter`, except negated.
**Example:**
```js
[1, 2, 3].reject(n => n % 2 === 0);
// [1, 3]
```
**Syntax**
```
reject(callback: Function, context?: Any) => Array
```
*/
if (!Array.prototype.reject) {
Array.prototype.reject = function (callbackFn) {
return this.reduce((newArray, item) => {
return !callbackFn(item) ? newArray.concat([item]) : newArray;
}, []);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment