Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
How to increment a set of 2 letters using GAS?

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!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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);

about 4 years ago · Juan Pablo Isaza Denunciar

0

In your situation, how about the following sample script?

const increase = s => {
  const idx = [...s].reduce((c, e, i, a) => (c += (e.charCodeAt(0) - 64) * Math.pow(26, a.length - i - 1)), -1);

  // Ref: https://stackoverflow.com/a/53678158
  columnIndexToLetter = (n) => (a = Math.floor(n / 26)) >= 0 ? columnIndexToLetter(a - 1) + String.fromCharCode(65 + (n % 26)) : "";

  return columnIndexToLetter(idx + 1);
};

const samples = ["A", "Z", "AA", "AZ", "ZZ"];
const res1 = samples.map(e => increase(e));
console.log(res1); // <--- [ 'B', 'AA', 'AB', 'BA', 'AAA' ]

// If you want to give one value, please use the following script.
const sample = "AA";
const res2 = increase(sample);
console.log(res2); // <--- AB

  • When this script is run, ["A", "Z", "AA", "AZ", "ZZ"] is converted to [ 'B', 'AA', 'AB', 'BA', 'AAA' ].

Reference:

  • map()
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda