Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// in: [['xxx'], ['yyy', 'zzz'], ...]
// out: [['xxx', 'yyy', ...], ['xxx', 'zzz', ...]]
function calcCombination(options) {
if (_.isEmpty(options)) {
return [[]]
}
let [firstOpt, ...rest] = options
let remainCombinations = calcCombination(rest)
return _.flatMap(remainCombinations, rc => {
return firstOpt.map(o1 => [o1, ...rc])
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment