main
|
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 20 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
1015 bytes
|
| Rev | Line | |
|---|
| [d24f17c] | 1 | var _curry2 =
|
|---|
| 2 | /*#__PURE__*/
|
|---|
| 3 | require("./internal/_curry2.js");
|
|---|
| 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 |
|
|---|
| 24 | var 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 |
|
|---|
| 48 | module.exports = xprod; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.