MCPcopy Create free account
hub / github.com/d3/d3-array / cross

Function cross

src/cross.js:17–33  ·  view source on GitHub ↗
(...values)

Source from the content-addressed store, hash-verified

15}
16
17export default function cross(...values) {
18 const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
19 values = values.map(arrayify);
20 const lengths = values.map(length);
21 const j = values.length - 1;
22 const index = new Array(j + 1).fill(0);
23 const product = [];
24 if (j < 0 || lengths.some(empty)) return product;
25 while (true) {
26 product.push(index.map((j, i) => values[i][j]));
27 let i = j;
28 while (++index[i] === lengths[i]) {
29 if (i === 0) return reduce ? product.map(reduce) : product;
30 index[i--] = 0;
31 }
32 }
33}

Callers 1

cross-test.jsFile · 0.90

Calls 1

reducerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…