Created
August 23, 2017 05:01
-
-
Save ryanlaws/381ac7145cdfe19cfb75826b10bf6714 to your computer and use it in GitHub Desktop.
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
// 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