summaryrefslogtreecommitdiff
path: root/lib/internal/filter.js
blob: 1a097f98b0717f51e62f41e26bd25db4b5e681ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import filter from 'lodash/filter';
import noop from 'lodash/noop';
import once from './once';

export default function _filter(eachfn, arr, iteratee, callback) {
    callback = once(callback || noop);
    var truthValues = new Array(arr.length);
    eachfn(arr, function (x, index, callback) {
        iteratee(x, function (err, v) {
            truthValues[index] = !!v;
            callback(err);
        });
    }, function (err) {
        if (err) return callback(err);
        callback(null, filter(arr, function (_, index) {
            return truthValues[index];
        }));
    });
}