Skip to content

Instantly share code, notes, and snippets.

@cedrickvstheworld
Created March 10, 2020 01:35
Show Gist options
  • Save cedrickvstheworld/c444720bd66b0b190e599777e302179f to your computer and use it in GitHub Desktop.
Save cedrickvstheworld/c444720bd66b0b190e599777e302179f to your computer and use it in GitHub Desktop.
1: A , 26: Z, 27: AA
function alphabetCounter(counter) {
counter = Math.abs(counter)
counter = !counter ? 1 : counter
let remainder = counter % 26
let quotient = Math.floor(counter / 26)
let result = remainder ? String.fromCharCode(64 + remainder) : (--quotient, 'Z');
return quotient ? alphabetCounter(quotient) + result : result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment