zipObj.js 954 B

1234567891011121314151617181920212223242526272829303132333435
  1. import _curry2 from "./internal/_curry2.js";
  2. /**
  3. * Creates a new object out of a list of keys and a list of values.
  4. * Key/value pairing is truncated to the length of the shorter of the two lists.
  5. * Note: `zipObj` is equivalent to `pipe(zip, fromPairs)`.
  6. *
  7. * @func
  8. * @memberOf R
  9. * @since v0.3.0
  10. * @category List
  11. * @sig [String] -> [*] -> {String: *}
  12. * @param {Array} keys The array that will be properties on the output object.
  13. * @param {Array} values The list of values on the output object.
  14. * @return {Object} The object made by pairing up same-indexed elements of `keys` and `values`.
  15. * @example
  16. *
  17. * R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}
  18. */
  19. var zipObj =
  20. /*#__PURE__*/
  21. _curry2(function zipObj(keys, values) {
  22. var idx = 0;
  23. var len = Math.min(keys.length, values.length);
  24. var out = {};
  25. while (idx < len) {
  26. out[keys[idx]] = values[idx];
  27. idx += 1;
  28. }
  29. return out;
  30. });
  31. export default zipObj;