1.0.3 • Published 8 years ago
combinatorial v1.0.3
combinatorial
Given n arrays, iterate over all possible combinations of values by taking a single value from each array.
Example
const combinatorial = require("combinatorial");
const a = [1, 2, 3];
const b = ['a', 'b', 'c'];
const c = ['A', 'B', 'C'];
const result = [];
combinatorial(a, b, c, (a, b, c) => {
result.push([a, b, c]);
});
// result will be the following:
[
[1, 'a', 'A'], [1, 'a', 'B'], [1, 'a', 'C'],
[1, 'b', 'A'], [1, 'b', 'B'], [1, 'b', 'C'],
[1, 'c', 'A'], [1, 'c', 'B'], [1, 'c', 'C'],
[2, 'a', 'A'], [2, 'a', 'B'], [2, 'a', 'C'],
[2, 'b', 'A'], [2, 'b', 'B'], [2, 'b', 'C'],
[2, 'c', 'A'], [2, 'c', 'B'], [2, 'c', 'C'],
[3, 'a', 'A'], [3, 'a', 'B'], [3, 'a', 'C'],
[3, 'b', 'A'], [3, 'b', 'B'], [3, 'b', 'C'],
[3, 'c', 'A'], [3, 'c', 'B'], [3, 'c', 'C']
]