Skip to content

Instantly share code, notes, and snippets.

@petercr
Created February 28, 2022 21:27
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 petercr/9358a3c9bd7c59daf6a9b9dace610d6d to your computer and use it in GitHub Desktop.
Save petercr/9358a3c9bd7c59daf6a9b9dace610d6d to your computer and use it in GitHub Desktop.
A function that takes in a String (in EN) and returns whether or not it is a pangram. Has all the letters of the alphabet in it.
function pangrams(s) {
// String to hold EN alphabet
const alphabet = "abcdefghijklmnopqrstuvwxyz";
// Regex to remove all white spaces
const removeSpaces = /\s/g;
// take String s and change to lowercase
s = s.toLowerCase().replace(removeSpaces, "");
// Loop over the alphabet and check for each letter
for (let index = 0; index < alphabet.length; index++) {
if (s.indexOf(alphabet[index]) === -1){
// if the letter is not found, return false
return "not pangram";
}
}
// return true if all letters are found
return "pangram";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment