pangram javascript 1

pangram javascript

function isPangram(string) {
    var regex = /([a-z])(?!.*\1)/gi;
    return (string.match(regex) || []).length === 26;
}

Here is what the above code is Doing:
1. The regex pattern is /([a-z])(?!.*\1)/gi.
2. The first part of the pattern, ([a-z]), matches any lowercase letter.
3. The second part of the pattern, (?!.*\1), is a negative lookahead.
4. The negative lookahead ensures that the match won’t be successful if the same letter appears later in the string.
5. The g flag makes the regex pattern test all occurrences in the string.
6. The i flag makes the regex case-insensitive.
7. The match() method returns an array of matches.
8. If the array is empty, the string doesn’t contain all the letters of the alphabet.
9. If the array contains 26 matches, the string contains all the letters of the alphabet.

Similar Posts