mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
/**
|
|
* lodash 4.0.0 (Custom Build) <https://lodash.com/>
|
|
* Build: `lodash modularize exports="npm" -o ./`
|
|
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
|
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
* Available under MIT license <https://lodash.com/license>
|
|
*/
|
|
var baseSet = require('lodash._baseset');
|
|
|
|
/**
|
|
* This method is like `_.fromPairs` except that it accepts two arrays,
|
|
* one of property names and one of corresponding values.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Array
|
|
* @param {Array} [props=[]] The property names.
|
|
* @param {Array} [values=[]] The property values.
|
|
* @returns {Object} Returns the new object.
|
|
* @example
|
|
*
|
|
* _.zipObject(['fred', 'barney'], [30, 40]);
|
|
* // => { 'fred': 30, 'barney': 40 }
|
|
*/
|
|
function zipObject(props, values) {
|
|
var index = -1,
|
|
length = props ? props.length : 0,
|
|
valsLength = values ? values.length : 0,
|
|
result = {};
|
|
|
|
while (++index < length) {
|
|
baseSet(result, props[index], index < valsLength ? values[index] : undefined);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
module.exports = zipObject;
|