mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Cleanup _.zipObject.
This commit is contained in:
12
lodash.js
12
lodash.js
@@ -4483,25 +4483,25 @@
|
|||||||
* @alias object
|
* @alias object
|
||||||
* @category Array
|
* @category Array
|
||||||
* @param {Array} props The property names.
|
* @param {Array} props The property names.
|
||||||
* @param {Array} [vals=[]] The property values.
|
* @param {Array} [values=[]] The property values.
|
||||||
* @returns {Object} Returns the new object.
|
* @returns {Object} Returns the new object.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.zipObject(['fred', 'barney'], [30, 40]);
|
* _.zipObject(['fred', 'barney'], [30, 40]);
|
||||||
* // => { 'fred': 30, 'barney': 40 }
|
* // => { 'fred': 30, 'barney': 40 }
|
||||||
*/
|
*/
|
||||||
function zipObject(props, vals) {
|
function zipObject(props, values) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = props ? props.length : 0,
|
length = props ? props.length : 0,
|
||||||
result = {};
|
result = {};
|
||||||
|
|
||||||
if (!vals && length && !isArray(props[0])) {
|
if (!values && length && !isArray(props[0])) {
|
||||||
vals = [];
|
values = [];
|
||||||
}
|
}
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var key = props[index];
|
var key = props[index];
|
||||||
if (vals) {
|
if (values) {
|
||||||
result[key] = vals[index];
|
result[key] = values[index];
|
||||||
} else if (key) {
|
} else if (key) {
|
||||||
result[key[0]] = key[1];
|
result[key[0]] = key[1];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user