source: node_modules/victory-vendor/lib-vendor/d3-array/src/cross.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 957 bytes
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = cross;
7function length(array) {
8 return array.length | 0;
9}
10function empty(length) {
11 return !(length > 0);
12}
13function arrayify(values) {
14 return typeof values !== "object" || "length" in values ? values : Array.from(values);
15}
16function reducer(reduce) {
17 return values => reduce(...values);
18}
19function cross(...values) {
20 const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
21 values = values.map(arrayify);
22 const lengths = values.map(length);
23 const j = values.length - 1;
24 const index = new Array(j + 1).fill(0);
25 const product = [];
26 if (j < 0 || lengths.some(empty)) return product;
27 while (true) {
28 product.push(index.map((j, i) => values[i][j]));
29 let i = j;
30 while (++index[i] === lengths[i]) {
31 if (i === 0) return reduce ? product.map(reduce) : product;
32 index[i--] = 0;
33 }
34 }
35}
Note: See TracBrowser for help on using the repository browser.