diff options
-rw-r--r-- | lib/internal/filter.js | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/lib/internal/filter.js b/lib/internal/filter.js index 35527e2..1158d6d 100644 --- a/lib/internal/filter.js +++ b/lib/internal/filter.js @@ -1,31 +1,19 @@ -import arrayMap from 'lodash/_arrayMap'; -import property from 'lodash/_baseProperty'; +import filter from 'lodash/_arrayFilter'; import noop from 'lodash/noop'; import once from './once'; export default function _filter(eachfn, arr, iteratee, callback) { callback = once(callback || noop); - var results = []; + var truthy = []; eachfn(arr, function (x, index, callback) { iteratee(x, function (err, v) { - if (err) { - callback(err); - } - else { - if (v) { - results.push({index: index, value: x}); - } - callback(); - } + truthy[index] = !!v; + callback(err); }); }, function (err) { - if (err) { - callback(err); - } - else { - callback(null, arrayMap(results.sort(function (a, b) { - return a.index - b.index; - }), property('value'))); - } + if (err) return callback(err); + callback(null, filter(arr, function (_, index) { + return truthy[index]; + })); }); } |