summaryrefslogtreecommitdiff
path: root/lib/internal/filter.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/filter.js')
-rw-r--r--lib/internal/filter.js19
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);
});
}