Initial commit
This commit is contained in:
commit
78f8d225ee
21173 changed files with 2907774 additions and 0 deletions
33
node_modules/d3-array/src/cross.js
generated
vendored
Normal file
33
node_modules/d3-array/src/cross.js
generated
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
function length(array) {
|
||||
return array.length | 0;
|
||||
}
|
||||
|
||||
function empty(length) {
|
||||
return !(length > 0);
|
||||
}
|
||||
|
||||
function arrayify(values) {
|
||||
return typeof values !== "object" || "length" in values ? values : Array.from(values);
|
||||
}
|
||||
|
||||
function reducer(reduce) {
|
||||
return values => reduce(...values);
|
||||
}
|
||||
|
||||
export default function cross(...values) {
|
||||
const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
|
||||
values = values.map(arrayify);
|
||||
const lengths = values.map(length);
|
||||
const j = values.length - 1;
|
||||
const index = new Array(j + 1).fill(0);
|
||||
const product = [];
|
||||
if (j < 0 || lengths.some(empty)) return product;
|
||||
while (true) {
|
||||
product.push(index.map((j, i) => values[i][j]));
|
||||
let i = j;
|
||||
while (++index[i] === lengths[i]) {
|
||||
if (i === 0) return reduce ? product.map(reduce) : product;
|
||||
index[i--] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue