summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Taylor <codemister99@yahoo.com>2016-10-16 14:52:43 -0400
committerCody Taylor <codemister99@yahoo.com>2016-10-16 14:52:43 -0400
commitddfcce4870491fb607d51f4096998a14fd09e705 (patch)
treef0027ed2b75c53ab3993451a7d822a1cd5736fd7
parent8695676064402b5744af9597ffc889c9e0cd15b9 (diff)
downloadasync-ddfcce4870491fb607d51f4096998a14fd09e705.tar.gz
Test filtering an object.
-rw-r--r--lib/internal/filter.js8
-rw-r--r--mocha_test/filter.js12
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/internal/filter.js b/lib/internal/filter.js
index 1158d6d..1a097f9 100644
--- a/lib/internal/filter.js
+++ b/lib/internal/filter.js
@@ -1,19 +1,19 @@
-import filter from 'lodash/_arrayFilter';
+import filter from 'lodash/filter';
import noop from 'lodash/noop';
import once from './once';
export default function _filter(eachfn, arr, iteratee, callback) {
callback = once(callback || noop);
- var truthy = [];
+ var truthValues = new Array(arr.length);
eachfn(arr, function (x, index, callback) {
iteratee(x, function (err, v) {
- truthy[index] = !!v;
+ truthValues[index] = !!v;
callback(err);
});
}, function (err) {
if (err) return callback(err);
callback(null, filter(arr, function (_, index) {
- return truthy[index];
+ return truthValues[index];
}));
});
}
diff --git a/mocha_test/filter.js b/mocha_test/filter.js
index 8b4b268..05d9d99 100644
--- a/mocha_test/filter.js
+++ b/mocha_test/filter.js
@@ -41,6 +41,18 @@ describe("filter", function () {
});
});
+ it('filter collection', function(done){
+ var a = {a: 3, b: 1, c: 2};
+ async.filter(a, function(x, callback){
+ callback(null, x % 2);
+ }, function(err, results){
+ expect(err).to.equal(null);
+ expect(results).to.eql([3,1]);
+ expect(a).to.eql({a: 3, b: 1, c: 2});
+ done();
+ });
+ });
+
it('filter error', function(done){
async.filter([3,1,2], function(x, callback){
callback('error');