1.0.0 • Published 10 years ago
@micro-js/filter v1.0.0
filter
Filter for various data types.
Installation
$ npm install @micro-js/filterUsage
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 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
1.0.0
10 years ago