server-json/node_modules/ramda/es/xprod.js
2024-11-01 08:00:42 +00:00

38 lines
No EOL
996 B
JavaScript

import _curry2 from "./internal/_curry2.js";
/**
* Creates a new list out of the two supplied by creating each possible pair
* from the lists.
*
* @func
* @memberOf R
* @since v0.1.0
* @category List
* @sig [a] -> [b] -> [[a,b]]
* @param {Array} as The first list.
* @param {Array} bs The second list.
* @return {Array} The list made by combining each possible pair from
* `as` and `bs` into pairs (`[a, b]`).
* @example
*
* R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
* @symb R.xprod([a, b], [c, d]) = [[a, c], [a, d], [b, c], [b, d]]
*/
var xprod = /*#__PURE__*/_curry2(function xprod(a, b) {
// = xprodWith(prepend); (takes about 3 times as long...)
var i = 0;
var ilen = a.length;
var j;
var jlen = b.length;
var result = Array(ilen * jlen);
while (i < ilen) {
j = 0;
while (j < jlen) {
result[i * jlen + j] = [a[i], b[j]];
j += 1;
}
i += 1;
}
return result;
});
export default xprod;