Skip to content
27 changes: 14 additions & 13 deletions String/CheckPangram.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/*
Pangram is a sentence that contains all the letters in the alphabet
https://en.wikipedia.org/wiki/Pangram
/**
* @function checkPangram
* @description - Pangram is a sentence that contains all the letters in the alphabet https://en.wikipedia.org/wiki/Pangram
* @param {string} string
* @returns {boolean}
*/

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
/**
* match all 26 alphabets using regex, with the help of:
* Capturing Group
* Character set
* Negative lookahead
* Dot & star
* Numeric reference
*/
return string.match(/([a-z])(?!.*\1)/gi).length === 26
}

export { checkPangram }