Running into a weird situation with lodash (v4.6.1) where I'm passing in a _.partialRight
function of _.padStart
into a _.map
callback and getting bum results.
Repro:
_.padStart("0", 2, "0");
// "00"
var f = _.partialRight(_.padStart, 2, "0");
f("0");
// "00"
_.map(["0"], function(s) { return f(s); });
// ["00"]
_.map(["0"], f);
// ["0"]
After diving into the lodash code that's doing this, we come to here:
function arrayMap(array, iteratee) {
var index = -1,
length = array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}
At this point iteratee
is the f
function declared above. Without diving into the code much further than that, I can only assume the arguments added on from _.partialRight
are getting appended after any and all arguments called on that function.
And now we reach the question part. Is this a bug/limitation with lodash or is there a better way to do this?