JSFiddle - React, Tailwind, and code Playground

by pierian_design

JavaScript

function getLetterNotationByNum(num) {
            var aAlfaBet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
            var sLetterNotation = '';
            var alfaLen = aAlfaBet.length;
            var remainder = 0;

            while (num > 0) {
                remainder = num % alfaLen;
                num = Math.floor(num / alfaLen);
                if (remainder === 0) {
                    num--;
                    sLetterNotation = sLetterNotation + aAlfaBet[alfaLen - 1];
                }else {
                    sLetterNotation = sLetterNotation + aAlfaBet[remainder-1];
                }
            }

            var sReversNotation = '';
            for (var i = sLetterNotation.length - 1; i >= 0; i--) {
                sReversNotation += sLetterNotation.charAt(i);
            }
            return sReversNotation;
        };


				console.log(getLetterNotationByNum(76));