mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
Added check pangram algorithm
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
/*
|
||||
Pangram is a sentence that contains all the letters in the alphabet
|
||||
https://en.wikipedia.org/wiki/Pangram
|
||||
*/
|
||||
|
||||
const checkPangram = (string) => {
|
||||
if (typeof string !== 'string') {
|
||||
throw new TypeError('The given value is not a string')
|
||||
}
|
||||
|
||||
const frequency = new Set()
|
||||
|
||||
for (const letter of string.toLowerCase()) {
|
||||
if (letter >= 'a' && letter <= 'z') {
|
||||
frequency.add(letter)
|
||||
}
|
||||
}
|
||||
|
||||
return frequency.size === 26
|
||||
}
|
||||
|
||||
export { checkPangram }
|
||||
|
Reference in New Issue
Block a user