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

136
Vistas
Encrypt using regex

I had a question I was able to solve for encrypting using regex and I like the solution just wondering if there is a way I can clean it up a bit? for the encryption im supposed to replace the vowels with these values and reverse the string adding aca to the end. just wondering if I can reduce the amount .replace lines thanks in advance

function encrypt(string) {
  let input=string.replace(/a/g, '0')
                  .replace(/e/g, '1')
                  .replace(/i/g, '2')
                  .replace(/o/g, '2')
                  .replace(/u/g, '3')
  return input.split("").reverse().join("")+"aca"
              
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You might use a single replace with a callback function, and in the function map the values to the numbers.

function encrypt(string) {
    const obj = {'a': 0, 'e': 1, 'i': 2, 'o': 2, 'u': 3};
    return string
        .replace(/[aeiou]/g, m => obj[m])
        .split("")
        .reverse()
        .join("")+"aca";
}

console.log(encrypt('this is an example, our example'));

about 4 years ago · Juan Pablo Isaza Denunciar

0

Known characters one to one replacement, regexp is not required.

const encrypt = (str) => {
  const map = { a: '0', e: '1', i: '2', o: '2', u: '3' };
  return str.split('').map(ch => map[ch] || ch).reverse().join('') + 'aca';
}

console.log(encrypt('hello mario'));

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