Skip to content

Instantly share code, notes, and snippets.

@thmain
Created December 25, 2022 05:30
Show Gist options
  • Save thmain/1fa0aae64e928f9c8a38b60e43802c6e to your computer and use it in GitHub Desktop.
Save thmain/1fa0aae64e928f9c8a38b60e43802c6e to your computer and use it in GitHub Desktop.
const combine = (instr, outstr, index) => {
for (var i = index; i < instr.length; i++) {
// append the character
outstr = outstr.concat(instr.charAt(i));
//print the result
console.log(outstr);
// make a recursive call at i + 1
combine(instr, outstr, i + 1);
// remove the character added in the first step
outstr = outstr.substr(0, outstr.length - 1);
}
};
combine("abc", "", 0); // a, ab, abc, ac, b, bc, c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment