Use arrayReduce in baseWrapperValue and _.invert, arrayEach in _.bindAll, and baseTimes in _.unzip.

This commit is contained in:
John-David Dalton
2015-08-30 04:27:29 -07:00
parent 7d6fcc75da
commit 98a97b1eaf

View File

@@ -2781,14 +2781,9 @@
if (result instanceof LazyWrapper) { if (result instanceof LazyWrapper) {
result = result.value(); result = result.value();
} }
var index = -1, return arrayReduce(actions, function(result, action) {
length = actions.length; return action.func.apply(action.thisArg, arrayPush([result], action.args));
}, result);
while (++index < length) {
var action = actions[index];
result = action.func.apply(action.thisArg, arrayPush([result], action.args));
}
return result;
} }
/** /**
@@ -5417,20 +5412,16 @@
if (!(array && array.length)) { if (!(array && array.length)) {
return []; return [];
} }
var index = -1, var length = 0;
length = 0;
array = arrayFilter(array, function(group) { array = arrayFilter(array, function(group) {
if (isObject(group) && isArrayLike(group)) { if (isObject(group) && isArrayLike(group)) {
length = nativeMax(group.length, length); length = nativeMax(group.length, length);
return true; return true;
} }
}); });
var result = Array(length); return baseTimes(length, function(index) {
while (++index < length) { return arrayMap(array, baseProperty(index));
result[index] = arrayMap(array, baseProperty(index)); });
}
return result;
} }
/** /**
@@ -6860,15 +6851,9 @@
* // => logs 'clicked docs' when the element is clicked * // => logs 'clicked docs' when the element is clicked
*/ */
var bindAll = restParam(function(object, methodNames) { var bindAll = restParam(function(object, methodNames) {
methodNames = baseFlatten(methodNames); arrayEach(baseFlatten(methodNames), function(key) {
var index = -1,
length = methodNames.length;
while (++index < length) {
var key = methodNames[index];
object[key] = createWrapper(object[key], BIND_FLAG, object); object[key] = createWrapper(object[key], BIND_FLAG, object);
} });
return object; return object;
}); });
@@ -9134,16 +9119,8 @@
*/ */
function invert(object, multiValue) { function invert(object, multiValue) {
multiValue = typeof multiValue == 'boolean' && multiValue; multiValue = typeof multiValue == 'boolean' && multiValue;
return arrayReduce(keys(object), function(result, key) {
var index = -1, var value = object[key];
props = keys(object),
length = props.length,
result = {};
while (++index < length) {
var key = props[index],
value = object[key];
if (multiValue) { if (multiValue) {
if (hasOwnProperty.call(result, value)) { if (hasOwnProperty.call(result, value)) {
result[value].push(key); result[value].push(key);
@@ -9154,8 +9131,8 @@
else { else {
result[value] = key; result[value] = key;
} }
} return result;
return result; }, {});
} }
/** /**