Skip to content

Commit

Permalink
Allow map to return objects
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed Aug 1, 2015
1 parent 1f97538 commit 0574aa9
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 @@ -1810,6 +1810,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 0574aa9

Please sign in to comment.