diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-11-11 15:28:39 -0500 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-11-11 15:59:29 -0500 |
commit | 9e5c087edd775b6c75ce88b55d826ac26ad6ab80 (patch) | |
tree | 46387d4d3411dd82430b8143a733233f72d7fe0c | |
parent | ddfcce4870491fb607d51f4096998a14fd09e705 (diff) | |
download | async-9e5c087edd775b6c75ce88b55d826ac26ad6ab80.tar.gz |
Avoid importing lodash/filter in async.filter
-rw-r--r-- | lib/internal/filter.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/internal/filter.js b/lib/internal/filter.js index 1a097f9..454cc54 100644 --- a/lib/internal/filter.js +++ b/lib/internal/filter.js @@ -1,19 +1,24 @@ -import filter from 'lodash/filter'; +import each from 'lodash/each'; +import isArrayLike from 'lodash/isArrayLike'; import noop from 'lodash/noop'; import once from './once'; -export default function _filter(eachfn, arr, iteratee, callback) { +export default function _filter(eachfn, coll, iteratee, callback) { callback = once(callback || noop); - var truthValues = new Array(arr.length); - eachfn(arr, function (x, index, callback) { + var truthValues = isArrayLike(coll) ? new Array(coll.length) : {}; + eachfn(coll, 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]; - })); + var result = []; + each(coll, function(_, index) { + if (truthValues[index] === true) { + result.push(coll[index]); + } + }); + callback(null, result); }); } |