(...arrayOfValues: PossibleValues)
| 539 | * @return The cartesian product. |
| 540 | */ |
| 541 | export function getCartesianProductOfValues(...arrayOfValues: PossibleValues): |
| 542 | PossibleValues { |
| 543 | assert(arrayOfValues.length > 0, 'arrayOfValues is empty'); |
| 544 | |
| 545 | for (const values of arrayOfValues) { |
| 546 | assert(Array.isArray(values), 'one of the values is not an array'); |
| 547 | assert(values.length > 0, 'one of the values is empty'); |
| 548 | } |
| 549 | |
| 550 | return arrayOfValues.reduce((products, values) => { |
| 551 | if (products.length === 0) { |
| 552 | return values.map(value => [value]); |
| 553 | } |
| 554 | |
| 555 | return values |
| 556 | .map(value => { |
| 557 | return products.map((prevValue) => [...prevValue, value]); |
| 558 | }) |
| 559 | .reduce((flattenedProduct, unflattenedProduct) => { |
| 560 | return flattenedProduct.concat(unflattenedProduct); |
| 561 | }, []); |
| 562 | }, [] as PossibleValues); |
| 563 | } |
no test coverage detected
searching dependent graphs…