1.0.0 • Published 9 years ago

@micro-js/filter v1.0.0

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

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