diff options
-rw-r--r-- | lib/internal/filter.js | 8 | ||||
-rw-r--r-- | mocha_test/filter.js | 12 |
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'); |