Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Change It Up KATA from codewars

I was doing this exercise from codewars: https://www.codewars.com/kata/58039f8efca342e4f0000023/train/javascript

Here the instructions:

Create a function that takes a string as a parameter and does the following, in this order:

Replaces every letter with the letter following it in the alphabet (see note below)

Makes any vowels capital

Makes any consonants lower case

Note:

the alphabet should wrap around, so Z becomes A in this kata, y isn't considered as a vowel. So, for example the string "Cat30" would return "dbU30" (Cat30 --> Dbu30 --> dbU30)

  • I get it pretty far but somehow the end result its not correct, this is my code:
function changer(str) { 
  // happy coding!
  let arr = str.split("")
  let newArr = [];
  
  let voRegEx = /[aeiouAEIOU]/g;
  let conRegEx = /[^aeiouAEIOU]/g;
  

  for(let i = 0; i < arr.length; i++) {
   
    if(arr[i] === "z" || arr[i] === "Z") { 
        newArr.push("A");
     }
    
    else if(arr[i].charCodeAt() >= 95 && arr[i].charCodeAt() <= 121
       || arr[i].charCodeAt() >= 65 && arr[i].charCodeAt() <= 89) {
      
       let char = String.fromCharCode(arr[i].charCodeAt()+1);
      
        console.log(char)
      
        if(conRegEx.test(char)) {
            newArr.push(char.toLowerCase());
        }
      
        if(voRegEx.test(char)) {
        newArr.push(char.toUpperCase());
        }
      } 
    else if(typeof(parseInt(arr[i])) === "number") newArr.push(arr[i]);
  }
 
  let newStr = newArr.join("")
    return newStr;
}

changer("Cat30");

Sry if its too messy, im new to coding and im not to clean yet. The thing is that i console.log(char) and show me the strings "D","b","u" but it seems like the "b" doesn´t get pushed to newArr but if i add 2 chars instead of 1 char now it gets pushed, like changer("Caat30"); now appears the "b" and if i add one other character the next will not appear, and the pattern repeats. I will gladly aprreciate any answer to my problem. Salute

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda