Skip to content
Browse files

Fix `.forEach` args remove key

  • Loading branch information...
1 parent 1d8bae5 commit d1ff0c759c41176a2d20d030c238c09ed6bcf5f1 @hokaccha committed Mar 12, 2012
Showing with 20 additions and 20 deletions.
  1. +4 −4 lib/chain-tiny.js
  2. +16 −16 test/forEach.js
View
8 lib/chain-tiny.js
@@ -91,9 +91,9 @@ Chain.prototype.forEach = function(fn) {
return self.chain(function(ary, next) {
var _chain = Chain();
var results = [];
- ary.forEach(function(val, i) {
+ ary.forEach(function(val) {
_chain.chain(function(_next) {
- fn.call(null, i, val, function(err, result) {
+ fn.call(null, val, function(err, result) {
results.push(result);
_next(err);
});
@@ -119,9 +119,9 @@ Chain.prototype.forEachParallel = function(fn) {
return self.chain(function(ary, next) {
var _chain = Chain();
var q = [];
- ary.forEach(function(val, i) {
+ ary.forEach(function(val) {
q.push(function(_next) {
- fn.call(null, i, val, function(err, result) {
+ fn.call(null, val, function(err, result) {
_next(err, result);
});
});
View
32 test/forEach.js
@@ -7,15 +7,15 @@ module.exports = nodeunit.testCase({
chain(function(next) {
next(null, ['foo', 'bar']);
})
- .forEach(function(key, val, next) {
+ .forEach(function(val, next) {
setTimeout(function() {
- next(null, key + ':' + val);
+ next(null, val);
}, 100);
})
.chain(function(results, next) {
t.equal(results.length, 2);
- t.equal(results[0], '0:foo');
- t.equal(results[1], '1:bar');
+ t.equal(results[0], 'foo');
+ t.equal(results[1], 'bar');
t.ok(Date.now() - start >= 190);
t.done();
})
@@ -26,47 +26,47 @@ module.exports = nodeunit.testCase({
chain(function(next) {
next(null, ['foo', 'bar']);
})
- .forEachParallel(function(key, val, next) {
+ .forEachParallel(function(val, next) {
setTimeout(function() {
- next(null, key + ':' + val);
+ next(null, val);
}, 100);
})
.chain(function(results, next) {
t.equal(results.length, 2);
- t.equal(results[0], '0:foo');
- t.equal(results[1], '1:bar');
+ t.equal(results[0], 'foo');
+ t.equal(results[1], 'bar');
t.ok(Date.now() - start < 190);
next();
})
.end(t.done);
},
'Chain.forEach()': function(t) {
var start = Date.now();
- chain.forEach(['foo', 'bar'], function(key, val, next) {
+ chain.forEach(['foo', 'bar'], function(val, next) {
setTimeout(function() {
- next(null, key + ':' + val);
+ next(null, val);
}, 100);
})
.chain(function(results, next) {
t.equal(results.length, 2);
- t.equal(results[0], '0:foo');
- t.equal(results[1], '1:bar');
+ t.equal(results[0], 'foo');
+ t.equal(results[1], 'bar');
t.ok(Date.now() - start >= 190);
next();
})
.end(t.done);
},
'Chain.forEachParallel()': function(t) {
var start = Date.now();
- chain.forEachParallel(['foo', 'bar'], function(key, val, next) {
+ chain.forEachParallel(['foo', 'bar'], function(val, next) {
setTimeout(function() {
- next(null, key + ':' + val);
+ next(null, val);
}, 100);
})
.chain(function(results, next) {
t.equal(results.length, 2);
- t.equal(results[0], '0:foo');
- t.equal(results[1], '1:bar');
+ t.equal(results[0], 'foo');
+ t.equal(results[1], 'bar');
t.ok(Date.now() - start < 190);
next();
})

0 comments on commit d1ff0c7

Please sign in to comment.
Something went wrong with that request. Please try again.