Created
February 28, 2022 21:27
-
-
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.
This file contains hidden or 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
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