Created
December 25, 2022 05:30
-
-
Save thmain/1fa0aae64e928f9c8a38b60e43802c6e to your computer and use it in GitHub Desktop.
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 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