diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-11-14 09:39:26 -0500 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-11-14 09:39:26 -0500 |
commit | e79952057cb1e439c396f0acc7dee5b635e40ab7 (patch) | |
tree | 7bbc46a936341618e864446297099055329f0b23 | |
parent | c626c99a14e175f46103cea5d19aaf2dc63ed893 (diff) | |
download | async-e79952057cb1e439c396f0acc7dee5b635e40ab7.tar.gz |
Revert back to previous filter implementation
-rw-r--r-- | lib/internal/filter.js | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/internal/filter.js b/lib/internal/filter.js index e191524..34cd722 100644 --- a/lib/internal/filter.js +++ b/lib/internal/filter.js @@ -1,27 +1,29 @@ -import isArrayLike from 'lodash/isArrayLike'; +import arrayMap from 'lodash/_arrayMap'; +import property from 'lodash/_baseProperty'; import noop from 'lodash/noop'; - import once from './once'; -import iterator from './iterator'; -export default function _filter(eachfn, coll, iteratee, callback) { +export default function _filter(eachfn, arr, iteratee, callback) { callback = once(callback || noop); - var truthValues = isArrayLike(coll) ? new Array(coll.length) : {}; - eachfn(coll, function (x, index, callback) { + var results = []; + eachfn(arr, function (x, index, callback) { iteratee(x, function (err, v) { - truthValues[index] = !!v; - callback(err); + if (err) { + callback(err); + } else { + if (v) { + results.push({index: index, value: x}); + } + callback(); + } }); }, function (err) { - if (err) return callback(err); - var result = []; - var nextElem = iterator(coll); - var elem; - while ((elem = nextElem()) !== null) { - if (truthValues[elem.key] === true) { - result.push(elem.value); - } + if (err) { + callback(err); + } else { + callback(null, arrayMap(results.sort(function (a, b) { + return a.index - b.index; + }), property('value'))); } - callback(null, result); }); } |