Created
November 29, 2018 03:19
-
-
Save HeGanjie/1b91d7894b2a76f51a3be5da419954ca 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
// 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