Skip to content

Instantly share code, notes, and snippets.

@rvbsanjose
Created May 22, 2020 23:58
Show Gist options
  • Save rvbsanjose/b6ef74ebf505e909fb84b2f5bee28f22 to your computer and use it in GitHub Desktop.
Save rvbsanjose/b6ef74ebf505e909fb84b2f5bee28f22 to your computer and use it in GitHub Desktop.
Print combinations
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);
@Ashik-Rahman100
Copy link

Awesome bro...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment