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

152
Vistas
Is there a way I can merge all my functions and for-loop into one function since I need (str) to be given by the site

I need this to work without Hard-Coding (str), but instead given by the actual site. Is it even possible? Yes I understand my Order is unusual, However it works lol. Thanks for any assistance I may receive. With this function I need to receive an string of works and return the next increment of the letter ex(a=b, b=c, e=f). Also returns any vowels as UpperCased. input: "hello3" Output: Ifmmp3

input: "fun times!" output: gvO Ujnft!

let str = ['f', 'u', 'n', ' ', '', 'i', 'm', 'e', 's', '!', 'n', 'n'];

function replaceLetter(letter) {
///above is fixed and cannot be edited

  return letter.replace(/([a-zA-Z])[^a-zA-Z]*$/, function (nextLetter) {
    var letter = nextLetter.charCodeAt(0);
    switch (letter) {
      case 90:
        return 'A';
      case 122:
        return 'a';
      default:
        return String.fromCharCode(++letter);
    }
  });
}
var vowels = 'aeiou';
let emptyStr = [];
let finalStr = '';
let holder = '';
for (const i of str) {
  [emptyStr.push(replaceLetter(i))].join().replaceAll(',', '');
}
for (let i = 0; i < emptyStr.length; i++) {
  if (vowels.indexOf(emptyStr[i]) >= 0) {
    finalStr += emptyStr[i].toUpperCase();
  } else {
    finalStr += emptyStr[i];
  }
}
console.log(finalStr);```
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

var vowels = "aeiou";
let received_str = "hello"; // the dynamic string you'll recieve

function replaceLetters(string) {
  ///above is fixed and cannot be edited
  let finalStr = "";
  let str = [...string];
  str.forEach((element) => {
    let nextLetter = element.replace(/([a-zA-Z])[^a-zA-Z]*$/, function (
      nextLetter
    ) {
      var letter = nextLetter.charCodeAt(0);
      switch (letter) {
        case 90:
          return "A";
        case 122:
          return "a";
        default:
          return String.fromCharCode(++letter);
      }
    });
    if (nextLetter !== ",") {
      if (vowels.indexOf(nextLetter) >= 0) {
        finalStr += nextLetter.toUpperCase();
      } else {
        finalStr += nextLetter;
      }
    }
  });
  return finalStr;
}

console.log(replaceLetters(received_str));

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