JSFiddle - React, Tailwind, and code Playground
JavaScript
var getAlpha = (function() {
var alphas = [null, "a"],
highest = [1];
function toAlpha(val) {
}
return function(decNum) {
if (alphas[decNum])
return alphas[decNum];
var d,
next,
carry,
i = alphas.length;
for(; i <= decNum; i++) {
next = "";
carry = true;
for(d = 0; d < highest.length; d++){
if (carry) {
if (highest[d] === 26) {
highest[d] = 1;
} else {
highest[d]++;
carry = false;
}
}
next = String.fromCharCode(
highest[d] + 96)
+ next;
}
if (carry) {
highest.push(1);
next = "a" + next;
}
alphas[i] = next;
}
return alphas[decNum];
};
})();
alert(getAlpha(27));
alert(getAlpha(100000));
for (var i=1; i < 10000; i++)
document.write(i + " " + getAlpha(i) + "<br>");