Generates a reducer that filters its accumulator by reducing each of its items to a boolean value. That is somewhat complicated to state, but easy to read as code:
function reduceFilter (fn) {
return function (state, value) {
return filter(predicate, state)
function predicate (item, key) {
return fn(item, value, key)
}
}
}
$ npm install @f/reduce-filter
var reduceFilter = require('@f/reduce-filter')
reduceFilter(isDivisbleBy)([1, 2, 3, 4, 5], 2) // -> [2, 4]
function isDivisbleBy (m, n) {
return m % n === 0
}
fn
- Accepts(item, value, key)
and returns a bool, indicating whether or not to retainitem
.
Returns: Returns a reducing function that accepts (state, value)
and returns a new container of type state
filtered by fn
.
MIT