Skip to content

Instantly share code, notes, and snippets.

@ryanlaws
Created August 23, 2017 05:01
Show Gist options
  • Save ryanlaws/381ac7145cdfe19cfb75826b10bf6714 to your computer and use it in GitHub Desktop.
Save ryanlaws/381ac7145cdfe19cfb75826b10bf6714 to your computer and use it in GitHub Desktop.
// No error checking or anything! Use with caution!
function addCombos(list, combos=[], dict={}) {
if (!list.length)
return combos.concat(dict);
let item = list[0];
let possibilities = getPossibilities(item);
possibilities.forEach(possibility => {
let subDict = addKvp(dict, item, possibility);
let subList = list.slice(1);
combos = addCombos(subList, combos, subDict);
});
return combos;
}
function addKvp(dict, key, value) {
return Object.assign({}, dict, { [key]: value });
}
function getPossibilities(item) {
return [true, false];
}
console.log(addCombos(["Chat", "Appointment", "C2C"]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment