summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCody Taylor <codemister99@yahoo.com>2016-10-05 10:00:14 -0400
committerCody Taylor <codemister99@yahoo.com>2016-10-05 10:45:25 -0400
commit8695676064402b5744af9597ffc889c9e0cd15b9 (patch)
treee7fa96120cb1e8f8222d9ac1539aecd6cefbe30d /lib
parent0d2dbf74b846aa923b492cd42e4d04e279dd32ec (diff)
downloadasync-8695676064402b5744af9597ffc889c9e0cd15b9.tar.gz
Improve filter by reducing complexity.
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/filter.js28
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];
+ }));
});
}