Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 3, 2019 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/772eae3d241201535e34759ca5e11c9a to your computer and use it in GitHub Desktop.
Save parzibyte/772eae3d241201535e34759ca5e11c9a to your computer and use it in GitHub Desktop.
/**
* 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