@davy-ext-shims/array.prototype.partition
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Array.prototype.partition

type annotation npm version dependency status dev dependency status License

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.

Package Sidebar

Install

npm i @davy-ext-shims/array.prototype.partition

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

89.6 kB

Total Files

39

Last publish

Collaborators

  • david50407