Created
October 3, 2019 17:16
-
-
Save parzibyte/772eae3d241201535e34759ca5e11c9a to your computer and use it in GitHub Desktop.
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
/** | |
* Saber si un carácter es una letra de la A a la Z | |
* con JavaScript | |
* | |
* https://parzibyte.me/blog | |
* | |
*/ | |
const esLetra = (caracter) => { | |
let ascii = caracter.toUpperCase().charCodeAt(0); | |
return ascii > 64 && ascii < 91; | |
}; | |
// Probar | |
const caracteres = ["A", "B", "0", "M", " ", "Y", "-", "L", "a", "b"]; | |
caracteres.forEach(caracter => { | |
console.log("¿'%s' es letra? %s", caracter, esLetra(caracter)); | |
}); | |
/* | |
Salida: | |
¿'A' es letra? true | |
¿'B' es letra? true | |
¿'0' es letra? false | |
¿'M' es letra? true | |
¿' ' es letra? false | |
¿'Y' es letra? true | |
¿'-' es letra? false | |
¿'L' es letra? true | |
¿'a' es letra? true | |
¿'b' es letra? true | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment