Solución
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