1.0.1 • Published 3 years ago

@davy-ext-shims/array.prototype.reject v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

array.prototype.reject

type annotation npm version dependency status dev dependency status License

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