Skip to content

Instantly share code, notes, and snippets.

@Alexzanderk
Created May 4, 2021 07:40
Show Gist options
  • Save Alexzanderk/e64e9cd395675e7e712677d319278976 to your computer and use it in GitHub Desktop.
Save Alexzanderk/e64e9cd395675e7e712677d319278976 to your computer and use it in GitHub Desktop.
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