Last active
April 12, 2017 12:28
-
-
Save evolutionxbox/cc09662c0597276bf6a32a11c0698732 to your computer and use it in GitHub Desktop.
Like filter, but negated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
# `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