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 |
|
---|
22 | var zip =
|
---|
23 | /*#__PURE__*/
|
---|
24 | _curry2(function zip(a, b) {
|
---|
25 | var rv = [];
|
---|
26 | var idx = 0;
|
---|
27 | var len = Math.min(a.length, b.length);
|
---|
28 |
|
---|
29 | while (idx < len) {
|
---|
30 | rv[idx] = [a[idx], b[idx]];
|
---|
31 | idx += 1;
|
---|
32 | }
|
---|
33 |
|
---|
34 | return rv;
|
---|
35 | });
|
---|
36 |
|
---|
37 | export default zip; |
---|