Pangram validator in one line
Christian Heilmann

Christian Heilmann @codepo8

About: That JavaScript/Browser guy who worked at Microsoft, Mozilla and Yahoo.

Location:
Berlin, Germany
Joined:
Oct 29, 2018

Pangram validator in one line

Publish Date: Nov 6 '23
5 2

For a quiz, I am playing with Pangrams, sentences that have all 26 letters of the alphabet in them. Using Set and some RegEx it is a one-liner in JavaScript to validate them (split into two lines for readability…).

const isPangram = s => new Set(
  s.toLowerCase().replace(/[^a-z]/g, '')
).size === 26;
Enter fullscreen mode Exit fullscreen mode

I've also put together a small tool for myself to write pangrams and check them whilst I type. You can see it in action here:

screen recording of the tool validating a sentence

Do you have a shorter solution?

Comments 2 total

  • GrahamTheDev
    GrahamTheDevNov 6, 2023

    TIL the word Pangram and I had fun playing with the tool. 🙏🏼💗

  • Yun OD
    Yun ODNov 8, 2023

    .match(/[a-z]/g) instead of .replace(/[^a-z]/g, '').split('')
    match() just return an array of matching strings.

Add comment