Created
May 22, 2020 23:58
-
-
Save rvbsanjose/b6ef74ebf505e909fb84b2f5bee28f22 to your computer and use it in GitHub Desktop.
Print combinations
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 printCombinations = (list, k, prefix = '') => { | |
if (!k) { | |
return console.log(prefix); | |
} | |
for (let i = 0; i < list.length; i++) { | |
printCombinations(list, k - 1, `${prefix}${list[i]}`); | |
} | |
}; | |
printCombinations(['a', 'b'], 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome bro...