Created
February 11, 2020 18:29
-
-
Save dherman/4d33477c256f96cc0cd67e6db8ccd23e to your computer and use it in GitHub Desktop.
quick n dirty generator of 2^6 combinations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ATTRIBUTES = ['A', 'B', 'C', 'D', 'E', 'F']; | |
// type attribute = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | |
// type value = "x" | "" | |
// type combo = [value] | |
function combos() { | |
return combosFrom(ATTRIBUTES, 0); | |
} | |
// ([attribute], index) -> [combo] | |
function combosFrom(attributes, from) { | |
// attribute | |
let attribute = attributes[from]; | |
if (from === attributes.length - 1) { | |
return ['x', '']; | |
} | |
// [combo] | |
let rest = combosFrom(attributes, from + 1); | |
// [combo] | |
let withAttributeOn = rest.map(combo => ['x'].concat(combo)); | |
// [combo] | |
let withAttributeOff = rest.map(combo => [''].concat(combo)); | |
// [combo] | |
return withAttributeOn.concat(withAttributeOff); | |
} | |
// ([combo]) -> [string] | |
function asCSV(combos) { | |
return combos.map(combo => combo.join(',')); | |
} | |
module.exports = function() { | |
asCSV(combos()).map(row => { console.log(row) }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment