Created
January 13, 2023 10:57
-
-
Save alefra88/d2ddeb8adce443d2c011619e228eee07 to your computer and use it in GitHub Desktop.
1) Programa una función que cuente el número de caracteres de una cadena de texto, pe. miFuncion("Hola Mundo") devolverá 10. si el dato no es string, pasarlo a string y contar los caracteres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contarChar = (dato) => { | |
if (typeof dato === "string") { | |
return dato.length; | |
} | |
if (typeof dato === "number") { | |
let numToString = dato.toString(); | |
return numToString.length; | |
} | |
if (typeof dato === "object") { | |
let objToString = dato.toString(); | |
return objToString.length; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment