Skip to content

Commit

Permalink
Merge pull request #873 from caolan/object-map
Browse files Browse the repository at this point in the history
Allow map to return objects
  • Loading branch information
aearly committed Oct 25, 2015
2 parents a1fdd1c + 0574aa9 commit 4ad7d30
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@

function _asyncMap(eachfn, arr, iterator, callback) {
callback = _once(callback || noop);
var results = [];
arr = arr || [];
var results = _isArrayLike(arr) ? [] : {};
eachfn(arr, function (value, index, callback) {
iterator(value, function (err, v) {
results[index] = v;
Expand Down
1 change: 1 addition & 0 deletions test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,7 @@ exports['map'] = {
callback(null, val * 2);
}, function (err, result) {
if (err) throw err;
test.equals(Object.prototype.toString.call(result), '[object Object]');
test.same(result, {a: 2, b: 4, c: 6});
test.done();
});
Expand Down

0 comments on commit 4ad7d30

Please sign in to comment.