main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
995 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import _curry2 from "./internal/_curry2.js";
|
---|
| 2 | /**
|
---|
| 3 | * Creates a new list out of the two supplied by creating each possible pair
|
---|
| 4 | * from the lists.
|
---|
| 5 | *
|
---|
| 6 | * @func
|
---|
| 7 | * @memberOf R
|
---|
| 8 | * @since v0.1.0
|
---|
| 9 | * @category List
|
---|
| 10 | * @sig [a] -> [b] -> [[a,b]]
|
---|
| 11 | * @param {Array} as The first list.
|
---|
| 12 | * @param {Array} bs The second list.
|
---|
| 13 | * @return {Array} The list made by combining each possible pair from
|
---|
| 14 | * `as` and `bs` into pairs (`[a, b]`).
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
|
---|
| 18 | * @symb R.xprod([a, b], [c, d]) = [[a, c], [a, d], [b, c], [b, d]]
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | var xprod =
|
---|
| 22 | /*#__PURE__*/
|
---|
| 23 | _curry2(function xprod(a, b) {
|
---|
| 24 | // = xprodWith(prepend); (takes about 3 times as long...)
|
---|
| 25 | var idx = 0;
|
---|
| 26 | var ilen = a.length;
|
---|
| 27 | var j;
|
---|
| 28 | var jlen = b.length;
|
---|
| 29 | var result = [];
|
---|
| 30 |
|
---|
| 31 | while (idx < ilen) {
|
---|
| 32 | j = 0;
|
---|
| 33 |
|
---|
| 34 | while (j < jlen) {
|
---|
| 35 | result[result.length] = [a[idx], b[j]];
|
---|
| 36 | j += 1;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | idx += 1;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | return result;
|
---|
| 43 | });
|
---|
| 44 |
|
---|
| 45 | export default xprod; |
---|
Note:
See
TracBrowser
for help on using the repository browser.