Skip to main content

Pangram2026-04-03

My Solution: Exercism Pangram solution

Instructions

Check if a sentence is a pangram, meaning it contains every letter of the English alphabet at least once. The check is case insensitive.

Solution

export function isPangram(sentence: string): boolean {
const letters = new Set(sentence.toLowerCase().match(/[a-z]/g));
return letters.size === 26;
}

Tests

// Happy path
console.log(isPangram('the quick brown fox jumps over the lazy dog')); // true

// False case
console.log(isPangram('a quick movement of the enemy will jeopardize five gunboats')); // false

// Edge case with underscores
console.log(isPangram('the_quick_brown_fox_jumps_over_the_lazy_dog')); // true

// Empty string
console.log(isPangram('')); // false

Mental Model

  • Set Usage: The Set object stores unique values. Here, it collects all unique lowercase alphabetic characters from the input sentence.
  • Regex Explanation: The regular expression /[a-z]/g matches all lowercase alphabetic characters in the string globally (i.e., across the entire string).
  • Equality Check: === (strict equality) ensures both value and type are the same, whereas == (loose equality) allows type coercion. In this solution, letters.size === 26 ensures the set contains exactly 26 unique letters without type conversion.