Created
February 25, 2022 05:24
-
-
Save shahidcodes/855fc420200dbf563eab4f9b5479503b to your computer and use it in GitHub Desktop.
Generate two alphabet continous sequences till `ZZ`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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