@davy-ext-shims/array.prototype.reject
v1.0.1
Published
Array.prototype.reject polyfill to select elements that do not pass the predictor
Downloads
98
Maintainers
Readme
array.prototype.reject
An intuitive method, Array.prototype.reject
, shim/polyfill that works as far down as ES3.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.
Because Array.prototype.reject
depends on a receiver (the “this” value), the main export takes the array to operate on as the first argument.
When using TypeScript and import with @davy-ext-shims/array.prototype.reject/auto
, global definition will be auto injected.
Example
var reject = require('@davy-ext-shims/array.prototype.reject')
var assert = require('assert')
assert.deepEqual(
reject([1, 2, 3], function (x) {
return x > 2
}),
[1, 2]
)
assert.deepEqual(
reject([1, 2, 3], function (x) {
return x < 2
}),
[2, 3]
)
var reject = require('@davy-ext-shims/array.prototype.reject')
var assert = require('assert')
var shimmedReject = reject.shim()
assert.equal(shimmedReject, reject.getPolyfill())
var arr = [1, 2, 3]
var isOdd = function (x) {
return x % 2 !== 0
}
assert.deepEqual(arr.reject(isOdd), reject(arr, isOdd))
Tests
Simply clone the repo, npm install
, and run npm test