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

192
Vistas
Convert Cases in a String

I am trying to create a function to reverse all cases in a string. All lower-case letters should be upper-case, and vice versa. For example: reverseCase("Happy Birthday") ➞ "hAPPY bIRTHDAY"

My code below doesn't work. :(

const functionX = X =>
  X === X.toLowerCase() ? X.toUpperCase() : X.toLowerCase();

function reverseCase(string) {
  const letters = string.split('');
  letters.forEach(functionX);
  return letters.join('');
}

console.log(reverseCase('Happy Birthday!'));

almost 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The forEach function does not return the output letter even though it executes the functionX for each input letter. You need to use map instead to return the letters.

Try like this:

const functionX = X =>
  X === X.toLowerCase() ? X.toUpperCase() : X.toLowerCase();

function reverseCase(string) {
  const letters = string.split('');
  return letters.map(functionX).join('');
}

console.log(reverseCase('Happy Birthday!'));

almost 4 years ago · Santiago Trujillo Denunciar

0

Hope its clear

function reverseCase(string) {
  const letters = string.split('');
  let resultLetters = letters.map(letter=> {
    let result = letter == letter.toLowerCase() ? letter.toUpperCase() : letter.toLowerCase();
    return result;
  });
  return resultLetters.join('');
}

console.log(reverseCase('Happy Birthday!'));

almost 4 years ago · Santiago Trujillo 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