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

208
Vistas
Find the correct word by incrementing letters in alphabet

Hi I came acroos this challenge from jschallenger page. I write the following code and It's working Fine unless any capital letter is passed. It seems to me ltr = "abcdefghijklmnopqrstuvwxyz" is not the right way. Could you please tell how can I improve my code?

function myf(a){
 let ltr = "abcdefghijklmnopqrstuvwxyz"
 let newstr =""

for(i=0; i<=a.split("").length-1; i++){
    let str = ltr.indexOf(a.charAt(i))+1
    
    let mystr = ltr.charAt(str )
    newstr += mystr
    }

 console.log(newstr)
}

myf("bnchm")  // result: coding
myf("bgddrd") // result: cheese
myf("sdrshmf")// result:testing
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You could calculate the letter by parsing a character, get the value in a 36 numbers system and add one. To ge the wanted value without carry take the rest of 36 and if zero add ten to get an 'a' (this was a 'z' before).

function convert(string) {
    let result = '';
    for (const c of string) {
        result += (((parseInt(c, 36) + 1)  % 36) || 10).toString(36);
    }
    return result;
}

console.log(convert("bnchmf"));   // coding
console.log(convert("bgddrd"));  // cheese
console.log(convert("sdrshmf")); // testing
console.log(convert("abcdefghijklmnopqrstuvwxyz")); // bcdefghijklmnopqrstuvwxyza

about 4 years ago · Juan Pablo Isaza Denunciar

0

Hope this code will help you.

const convert = (str) => {
  let result = "";
  for (const char of str) {
    result += String.fromCharCode(
      char.charCodeAt(0) + 1 === 123
        ? 97
        : char.charCodeAt(0) + 1 === 91
        ? 65
        : char.charCodeAt(0) + 1
    );
  }
  console.log(result);
};

convert("XYZ");
convert("bgddrz");
convert("bnchmf");

about 4 years ago · Juan Pablo Isaza Denunciar

0

     // remember capitals
      var obj={};
      for(let itr=0;itr<arg.toString().length;itr++){
       if(arg[itr]==arg[itr].toUpperCase()){
          obj[itr]=true // isUpperCase
       }
        // toLowerCase
         for(let iter=0;iter<String(arg).toLowerCase().split('');iter++){
       // your code
       }

The remembered capitals are used to restore uppercase letters before logging the result.

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