35 lines
954 B
JavaScript
35 lines
954 B
JavaScript
|
import _curry2 from "./internal/_curry2.js";
|
||
|
/**
|
||
|
* Creates a new object out of a list of keys and a list of values.
|
||
|
* Key/value pairing is truncated to the length of the shorter of the two lists.
|
||
|
* Note: `zipObj` is equivalent to `pipe(zip, fromPairs)`.
|
||
|
*
|
||
|
* @func
|
||
|
* @memberOf R
|
||
|
* @since v0.3.0
|
||
|
* @category List
|
||
|
* @sig [String] -> [*] -> {String: *}
|
||
|
* @param {Array} keys The array that will be properties on the output object.
|
||
|
* @param {Array} values The list of values on the output object.
|
||
|
* @return {Object} The object made by pairing up same-indexed elements of `keys` and `values`.
|
||
|
* @example
|
||
|
*
|
||
|
* R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}
|
||
|
*/
|
||
|
|
||
|
var zipObj =
|
||
|
/*#__PURE__*/
|
||
|
_curry2(function zipObj(keys, values) {
|
||
|
var idx = 0;
|
||
|
var len = Math.min(keys.length, values.length);
|
||
|
var out = {};
|
||
|
|
||
|
while (idx < len) {
|
||
|
out[keys[idx]] = values[idx];
|
||
|
idx += 1;
|
||
|
}
|
||
|
|
||
|
return out;
|
||
|
});
|
||
|
|
||
|
export default zipObj;
|