mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Bump to v4.1.0.
This commit is contained in:
17
zipObject.js
17
zipObject.js
@@ -1,4 +1,5 @@
|
||||
import baseSet from './internal/baseSet';
|
||||
import assignValue from './_assignValue';
|
||||
import baseZipObject from './_baseZipObject';
|
||||
|
||||
/**
|
||||
* This method is like `_.fromPairs` except that it accepts two arrays,
|
||||
@@ -12,19 +13,11 @@ import baseSet from './internal/baseSet';
|
||||
* @returns {Object} Returns the new object.
|
||||
* @example
|
||||
*
|
||||
* _.zipObject(['fred', 'barney'], [30, 40]);
|
||||
* // => { 'fred': 30, 'barney': 40 }
|
||||
* _.zipObject(['a', 'b'], [1, 2]);
|
||||
* // => { 'a': 1, 'b': 2 }
|
||||
*/
|
||||
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;
|
||||
return baseZipObject(props || [], values || [], assignValue);
|
||||
}
|
||||
|
||||
export default zipObject;
|
||||
|
||||
Reference in New Issue
Block a user