Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- // Driver Code
- let input = "1123".split("");
- let output = [];
- printCombinations(input, 0, output, 0);
- });
- function getAlpabet(num) {
- const legend = '0ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- return legend[num];
- }
- function printCombinations(input,index,output,outLength) {
- // no more digits left in input string
- if (input.length == index) {
- // print output string & return
- var y = output.join("").split(" ").filter(function (x) {
- return x <= 26
- })
- if (y.length != input.length) {
- if (y.join("")) {
- var label = ''
- var ou = output.join("").split(" ").map(function (x) {
- if (Number(x) > 0) {
- label += getAlpabet(Number(x))
- }
- return Number(x) > 0 ? getAlpabet(Number(x)) +' = '+ Number(x) + ', ' : ""
- }).join("")
- console.log(label +'// '+ ou)
- }
- }
- return;
- }
- // place current digit in input string
- output[outLength] = input[index];
- // separate next digit with a space
- output[outLength + 1] = ' ';
- printCombinations(input, index + 1, output, outLength + 2);
- // if next digit exists make a
- // call without including space
- if(input.length != index + 1) {
- printCombinations(input, index + 1, output, outLength + 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement