Skip to content

Commit

Permalink
simplify index tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Jun 1, 2016
1 parent 5f6e76d commit 611a442
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/internal/map.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import isArrayLike from 'lodash/isArrayLike';
import getIterator from './getIterator';
import noop from 'lodash/noop';
import okeys from 'lodash/keys';
import indexOf from 'lodash/_baseIndexOf';
import once from './once';

export default function _asyncMap(eachfn, arr, iteratee, callback) {
callback = once(callback || noop);
arr = arr || [];
var results = [];
var keys;
if (!isArrayLike(arr) && !getIterator(arr)) {
keys = okeys(arr);
}
var counter = 0;

eachfn(arr, function (value, index, callback) {
eachfn(arr, function (value, _, callback) {
var index = counter++;
iteratee(value, function (err, v) {
var idx = keys ? indexOf(keys, index, 0) : index;
results[idx] = v;
results[index] = v;
callback(err);
});
}, function (err) {
Expand Down

0 comments on commit 611a442

Please sign in to comment.