mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Rename _.object to _.zipObject and make _.object an alias of _.zipObject.
Former-commit-id: 7ae3c9d8be32b1430945ffeafc20c740f1d7f409
This commit is contained in:
78
lodash.js
78
lodash.js
@@ -705,12 +705,12 @@
|
||||
};
|
||||
}
|
||||
if (argCount === 4) {
|
||||
return function(accumulator, value, index, object) {
|
||||
return func.call(thisArg, accumulator, value, index, object);
|
||||
return function(accumulator, value, index, collection) {
|
||||
return func.call(thisArg, accumulator, value, index, collection);
|
||||
};
|
||||
}
|
||||
return function(value, index, object) {
|
||||
return func.call(thisArg, value, index, object);
|
||||
return function(value, index, collection) {
|
||||
return func.call(thisArg, value, index, collection);
|
||||
};
|
||||
}
|
||||
return func;
|
||||
@@ -3667,39 +3667,6 @@
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an object composed from arrays of `keys` and `values`. Pass either
|
||||
* a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or
|
||||
* two arrays, one of `keys` and one of corresponding `values`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Arrays
|
||||
* @param {Array} keys The array of keys.
|
||||
* @param {Array} [values=[]] The array of values.
|
||||
* @returns {Object} Returns an object composed of the given keys and
|
||||
* corresponding values.
|
||||
* @example
|
||||
*
|
||||
* _.object(['moe', 'larry'], [30, 40]);
|
||||
* // => { 'moe': 30, 'larry': 40 }
|
||||
*/
|
||||
function object(keys, values) {
|
||||
var index = -1,
|
||||
length = keys ? keys.length : 0,
|
||||
result = {};
|
||||
|
||||
while (++index < length) {
|
||||
var key = keys[index];
|
||||
if (values) {
|
||||
result[key] = values[index];
|
||||
} else {
|
||||
result[key[0]] = key[1];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array of numbers (positive and/or negative) progressing from
|
||||
* `start` up to but not including `end`.
|
||||
@@ -4051,6 +4018,40 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an object composed from arrays of `keys` and `values`. Pass either
|
||||
* a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or
|
||||
* two arrays, one of `keys` and one of corresponding `values`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @alias object
|
||||
* @category Arrays
|
||||
* @param {Array} keys The array of keys.
|
||||
* @param {Array} [values=[]] The array of values.
|
||||
* @returns {Object} Returns an object composed of the given keys and
|
||||
* corresponding values.
|
||||
* @example
|
||||
*
|
||||
* _.zipObject(['moe', 'larry'], [30, 40]);
|
||||
* // => { 'moe': 30, 'larry': 40 }
|
||||
*/
|
||||
function zipObject(keys, values) {
|
||||
var index = -1,
|
||||
length = keys ? keys.length : 0,
|
||||
result = {};
|
||||
|
||||
while (++index < length) {
|
||||
var key = keys[index];
|
||||
if (values) {
|
||||
result[key] = values[index];
|
||||
} else {
|
||||
result[key[0]] = key[1];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
@@ -5010,7 +5011,6 @@
|
||||
lodash.memoize = memoize;
|
||||
lodash.merge = merge;
|
||||
lodash.min = min;
|
||||
lodash.object = object;
|
||||
lodash.omit = omit;
|
||||
lodash.once = once;
|
||||
lodash.pairs = pairs;
|
||||
@@ -5034,6 +5034,7 @@
|
||||
lodash.without = without;
|
||||
lodash.wrap = wrap;
|
||||
lodash.zip = zip;
|
||||
lodash.zipObject = zipObject;
|
||||
|
||||
// add aliases
|
||||
lodash.collect = map;
|
||||
@@ -5041,6 +5042,7 @@
|
||||
lodash.each = forEach;
|
||||
lodash.extend = assign;
|
||||
lodash.methods = functions;
|
||||
lodash.object = zipObject;
|
||||
lodash.select = filter;
|
||||
lodash.tail = rest;
|
||||
lodash.unique = uniq;
|
||||
|
||||
Reference in New Issue
Block a user