What I'm trying to achieve is to get a combination of alphabets from a given input number. E.g. if I give input 111, the output should be ['AAA','KA','AK'] . If the input signal is 1111, the output should be ['AAAA','KAA','AKA','AAK','KK'] . Partial working code is as follows, where I get ['K','K'] for input 111:
<html> <head> <h1>Javascript</h1> </head> <body> <script> var dataset = {A:'1',B:'2',C:'3',D:'4',E:'5',F:'6',G:'7',H:'8',I:'9', J:'10',K:'11',L:'12',M:'13',N:'14',O:'15',P:'16',Q:'17',R:'18', S:'19',T:'20',U:'21',V:'22',W:'23',X:'24',Y:'25',Z:'26'}; var arr = []; var z; var result = []; var find = function(input){ for(var key in dataset) { if(dataset[key] === input) { return key; } } } var foo = function(x){ z = x.toString(); for(var i=0;i<z.length;i++){ arr.push(z.charAt(i)); } for(var i=0;i<arr.length;i++){ if(arr[i]+arr[i+1] <= 26){ var returnedkey = find(arr[i]+arr[i+1]); result.push(returnedkey); } } } foo(111); console.log(arr); console.log(result); </script> </body>
I am confused how to proceed further, and which is the correct method, Thanks in advance!