summaryrefslogtreecommitdiff
path: root/lib/internal/filter.js
blob: 83242fa4f7a41270fed5bbcd993c271459dfcfb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';

import arrayMap from 'lodash/internal/arrayMap';
import property from 'lodash/utility/property';

export default function _filter(eachfn, arr, iterator, callback) {
    var results = [];
    eachfn(arr, function (x, index, callback) {
        iterator(x, function (v) {
            if (v) {
                results.push({index: index, value: x});
            }
            callback();
        });
    }, function () {
        callback(arrayMap(results.sort(function (a, b) {
            return a.index - b.index;
        }), property('value')));
    });
}