@micro-js/filter

1.0.0 • Public • Published

filter

Build status Git tag NPM version Code style

Filter for various data types.

Installation

$ npm install @micro-js/filter

Usage

var filter = require('@micro-js/filter')

filter(isEven, [1, 2, 3, 4, 5]) // -> [2, 4]
filter(isEven, {a: 1, b: 2, c: 3, d: 4, e: 5}) // -> {b: 2, d: 4}

function isEven (n) {
  return n % 2 === 0
}

API

filter(fn, val)

  • fn - Predicate function. Called like fn(val, key) returns a boolean indicating whether to keep that key/value pair.
  • val - A container of some kind (object or array at the moment)

Returns: A new container of the same type as val containing only the key/value pairs that fn(val, key) returned truthy for.

License

MIT

/@micro-js/filter/

    Package Sidebar

    Install

    npm i @micro-js/filter

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • micro-js