Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
¿Cómo incrementar un conjunto de 2 letras usando GAS?

¿Cómo podría modificarse este para que pudiera incrementar un conjunto de dos letras, para que se viera así:

AA, AB, AC...AZ, BA, BB, BC, etc

Esto se toma prestado de tckmn , pero solo se refiere a una letra.

 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] }

¡Aprecio tu ayuda!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Solo necesitas dos bucles. Uno para iterar sobre el alfabeto y el segundo para iterar sobre el alfabeto en cada iteración del primer bucle.

 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 Report

0

En su situación, ¿qué tal el siguiente script de muestra?

 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

  • Cuando se ejecuta este script, ["A", "Z", "AA", "AZ", "ZZ"] se convierte en [ 'B', 'AA', 'AB', 'BA', 'AAA' ] .

Referencia:

  • mapa()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!