How could this one be tweaked so that it could increment a set of two letters, so that it’d look like this:
AA, AB, AC...AZ, BA, BB, BC, etc
This is borrowed from tckmn, but it addresses one letter only.
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
function incrementChar(c) {
var index = alphabet.indexOf(c)
if (index == -1) return -1 // or whatever error value you want
return alphabet[index + 1 % alphabet.length]
}
Appreciate your help!
>Solution :
You just need two loops. One to iterate over the alphabet, and the second to iterate over the alphabet on each iteration of the first loop.
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const arr = [];
for (let i = 0; i < alphabet.length; i++) {
for (let j = 0; j < alphabet.length; j++) {
arr.push(`${alphabet[i]}${alphabet[j]}`);
}
}
console.log(arr);