@davy-ext-shims/array.prototype.partition
v1.0.0
Published
Array.prototype.partition polyfill splitting elements into pair of lists by predictor
Downloads
2
Maintainers
Readme
Array.prototype.partition
An intuitive method, Array.prototype.partition
, shim/polyfill that works as far down as ES3.
Array.prototype.partition
will split elements into pair of lists: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the proposal.
Because Array.prototype.partition
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.partition/auto
, global definition will be auto injected.
Example
var partition = require('@davy-ext-shims/array.prototype.partition')
var assert = require('assert')
assert.deepEqual(
partition([1, 2, 3, 4], function (x) {
return x < 3
}),
[[1, 2], [3, 4]]
)
assert.deepEqual(
partition([1, 2, 3, 4], function (x) {
return x % 2 !== 0
}),
[[1, 3], [2, 4]]
)
var partition = require('@davy-ext-shims/array.prototype.partition')
var assert = require('assert')
var shimmedPartition = partition.shim()
assert.equal(shimmedPartition, partition.getPolyfill())
var arr = [1, 2, 3, 4]
var isOdd = function (x) {
return x % 2 !== 0
}
assert.deepEqual(arr.partition(isOdd), partition(arr, isOdd))
Tests
TBD.