1.1.1 • Published 10 years ago
@f/filter v1.1.1
filter
Filter for various data types.
Installation
$ npm install @f/filterUsage
var filter = require('@f/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 likefn(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