UNPKG

1.01 kBJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4/**
5 * Creates a new list out of the two supplied by creating each possible pair
6 * from the lists.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.1.0
11 * @category List
12 * @sig [a] -> [b] -> [[a,b]]
13 * @param {Array} as The first list.
14 * @param {Array} bs The second list.
15 * @return {Array} The list made by combining each possible pair from
16 * `as` and `bs` into pairs (`[a, b]`).
17 * @example
18 *
19 * R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
20 * @symb R.xprod([a, b], [c, d]) = [[a, c], [a, d], [b, c], [b, d]]
21 */
22
23
24var xprod =
25/*#__PURE__*/
26_curry2(function xprod(a, b) {
27 // = xprodWith(prepend); (takes about 3 times as long...)
28 var idx = 0;
29 var ilen = a.length;
30 var j;
31 var jlen = b.length;
32 var result = [];
33
34 while (idx < ilen) {
35 j = 0;
36
37 while (j < jlen) {
38 result[result.length] = [a[idx], b[j]];
39 j += 1;
40 }
41
42 idx += 1;
43 }
44
45 return result;
46});
47
48module.exports = xprod;
\No newline at end of file