Possible Duplicate:
Xnary (like binary but different) counting
In JavaScript, I want to implement a numbering scheme in JavaScript so that 1 is A, 2 is B, .... 26 is Z, 27 is AA, 28 is AB .....
For that, heres the code:
function convertor(n){
var x = n-1,
baseCharCode = "A".charCodeAt(0);
var arr = x.toString(26).split(''),
len = arr.length;
return arr.map(function(val,i){
val = parseInt(val,26);
if( (i === 0) && ( len > 1)){
val = val-1;
}
return String.fromCharCode(baseCharCode + val);
}).join('');
}
It seems to work fine, but any ideas to optimize it or another way of implementing it ?