Created
May 4, 2021 07:40
-
-
Save Alexzanderk/e64e9cd395675e7e712677d319278976 to your computer and use it in GitHub Desktop.
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
var nextChar = c=>c?String.fromCharCode(c.charCodeAt(0)+1):'A'; | |
var nextCol = s=>s.replace(/([^Z]?)(Z*)$/, (_,a,z)=>nextChar(a) + z.replace(/Z/g,'A')); | |
//test: | |
nextCol(''); //A | |
nextCol('A'); //B | |
nextCol('Z'); //AA | |
nextCol('AA'); //AB | |
nextCol('XYZ'); //XZA | |
nextCol('ZZZZ'); //AAAAA | |
//output: A,B,C,...,ZZ | |
for(var i=0, s=''; i<702; i++){ | |
s = nextCol(s); | |
console.log(s); | |
} | |
//output: A,B,C,...,ZZZZ | |
for(var i=0, s=''; i<475254; i++){ | |
s = nextCol(s); | |
console.log(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment