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
Setmade from the lowercased characters of theinputthat only match the regular expression pattern for letters froma-z. - The function returns if the
sizeof theSetis26. If the number of unique letters in theSetis equal to the26letters 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.
4th Sep 2024
·
Found it useful?