Skip to content

Commit

Permalink
Merge pull request #801 from megawac/simpl-reject
Browse files Browse the repository at this point in the history
Implement _reject via _filter
  • Loading branch information
aearly committed Jun 24, 2015
2 parents bd8325f + f5984d8 commit 4722bb5
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,24 +416,11 @@
async.filterSeries = doSeries(_filter);

function _reject(eachfn, arr, iterator, callback) {
var results = [];
arr = _map(arr, function (x, i) {
return {index: i, value: x};
});
eachfn(arr, function (x, index, callback) {
iterator(x.value, function (v) {
if (!v) {
results.push(x);
}
callback();
_filter(eachfn, arr, function(value, cb) {
iterator(value, function(v) {
cb(!v);
});
}, function () {
callback(_map(results.sort(function (a, b) {
return a.index - b.index;
}), function (x) {
return x.value;
}));
});
}, callback);
}
async.reject = doParallel(_reject);
async.rejectSeries = doSeries(_reject);
Expand Down

0 comments on commit 4722bb5

Please sign in to comment.