Last active
February 18, 2016 07:10
-
-
Save voltrevo/124d98ee6aac47029cbe to your computer and use it in GitHub Desktop.
This file contains hidden or 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 enumerateChoices = (sets) => { | |
if (sets.length === 0) { | |
return [[]]; | |
} | |
const subChoices = enumerateChoices(sets.slice(1)); | |
return [].concat(...sets[0].map( | |
choice => subChoices.map(choices => [choice].concat(choices)) | |
)); | |
}; | |
export default enumerateChoices; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
Output: