Solución

@christamdev
·hace 2dTypeScript
solution.tsTypeScript
function camelToSnake(text: string): string {
  // camelCase -> camel_case
  if (!text.length) return ""

  const textLowercase = text.toLowerCase();
  const textArray = text.split('');
  const textLowerArray = textLowercase.split('');

  let camel = '';

  for (let i = 0; i < textArray.length; i++) {
    if(textArray[i] !== textLowerArray[i]){
      // entonces es mayuscula
      camel += `_${textLowerArray[i]}`
    } else {
      camel += textArray[i];
    }
  }


  return camel;
}

// No modificar: necesario para evaluar el resultado.
export { camelToSnake };
0respuestas
Respuestas
0

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.
Markdown