summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2015-08-01 15:37:41 -0400
committerGraeme Yeates <yeatesgraeme@gmail.com>2015-08-01 15:44:11 -0400
commit0574aa90d696e22e5c870192ba8ec22e4e0e9eb2 (patch)
treefa18563af711b761ff75d10ff53b23882d2086c5
parent1f97538586e09ce76168fa1ceb04288fd958b0a0 (diff)
downloadasync-object-map.tar.gz
Allow map to return objectsobject-map
-rw-r--r--lib/async.js3
-rwxr-xr-xtest/test-async.js1
2 files changed, 3 insertions, 1 deletions
diff --git a/lib/async.js b/lib/async.js
index 9c2b6af..208e602 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -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;
diff --git a/test/test-async.js b/test/test-async.js
index dc7d949..23aa2b9 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -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();
});