export function isPangram(input) {
return new Set(input.toLowerCase().match(/[a-z]/g)).size === 26;
}
This approach creates a Set
of the unique letters in the input
and tests its size to determine the result.
- It first creates a new
Set
made from the lowercased characters of theinput
that only match the regular expression pattern for letters froma
-z
. - The function returns if the
size
of theSet
is26
. If the number of unique letters in theSet
is equal to the26
letters in the alphabet, then the function will returntrue
.
Shortening
When the body of a function is a single expression, the function can be implemented as an arrow function, like so
export const isPangram = (input) =>
new Set(input.toLowerCase().match(/[a-z]/g)).size === 26;
Notice that return
and the curly braces are not needed.
13th Nov 2024
·
Found it useful?