You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1009 B

4 years ago
  1. import _curry2 from "./internal/_curry2.js";
  2. /**
  3. * Creates a new list out of the two supplied by pairing up equally-positioned
  4. * items from both lists. The returned list is truncated to the length of the
  5. * shorter of the two input lists.
  6. * Note: `zip` is equivalent to `zipWith(function(a, b) { return [a, b] })`.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.1.0
  11. * @category List
  12. * @sig [a] -> [b] -> [[a,b]]
  13. * @param {Array} list1 The first array to consider.
  14. * @param {Array} list2 The second array to consider.
  15. * @return {Array} The list made by pairing up same-indexed elements of `list1` and `list2`.
  16. * @example
  17. *
  18. * R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]
  19. * @symb R.zip([a, b, c], [d, e, f]) = [[a, d], [b, e], [c, f]]
  20. */
  21. var zip =
  22. /*#__PURE__*/
  23. _curry2(function zip(a, b) {
  24. var rv = [];
  25. var idx = 0;
  26. var len = Math.min(a.length, b.length);
  27. while (idx < len) {
  28. rv[idx] = [a[idx], b[idx]];
  29. idx += 1;
  30. }
  31. return rv;
  32. });
  33. export default zip;