Skip to content

Instantly share code, notes, and snippets.

@shahidcodes
Created February 25, 2022 05:24
Show Gist options
  • Save shahidcodes/855fc420200dbf563eab4f9b5479503b to your computer and use it in GitHub Desktop.
Save shahidcodes/855fc420200dbf563eab4f9b5479503b to your computer and use it in GitHub Desktop.
Generate two alphabet continous sequences till `ZZ`
let startCharCode = 64
const letters = [
'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'
]
function alphabetSequence(i) {
let prefix = ''
const letterIteration = Math.ceil(i/26) - 2
if(letterIteration >= 0) {
prefix = letters[letterIteration];
}
let newIndex = i - ((letterIteration + 1) * 26)
let letter = String.fromCharCode(newIndex+startCharCode)
return `${prefix}${letter}`
}
for(let i=1; i<=30; i++) {
const letter = alphabetSequence(i)
console.log(letter)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment