16 Apr 2023

Check if a Sentence is a Panagram

Taken from Exercism

Your task is to figure out if a sentence is a pangram.

A pangram is a sentence using every letter of the alphabet at least once. It is case insensitive, so it doesn’t matter if a letter is lower-case (e.g. k) or upper-case (e.g. K).

For this exercise we only use the basic letters used in the English alphabet: a to z.


This is the answer I came up with:

// typescript

function isPangram(sentence: string): boolean {
  // Create a Set from the alphabet
  let alphabet: string = 'abcdefghijklmnopqrstuvwxyz'
  let alphaSet: Set<string> = new Set([...alphabet])

  // Convert the sentence to lowercase, filter against the alphabet Set
  let rawSentenceArray: Array<string> = [...sentence.toLowerCase()]
  let filteredSentenceArray: Array<string> = []

  rawSentenceArray.forEach(element => {
    if (alphaSet.has(element)) {

  // Convert the filtered sentence Array into a Set, 
  let sentenceSet: Set<string> = new Set([...filteredSentenceArray])

  // Compare the two Sets via number of elements (since 26 chars in alphabet)
  return (sentenceSet.size === alphaSet.size) ? true : false

The tests checked for underscores, numbers, and punctuation but the implementation covered all edge cases since filtering against a Set is discriminative.


Solution tested in REPL:


Webmentions & Comments

Copyright © Paramdeo Singh · Built with Jekyll in 🇬🇾 · All Rights Reserved

[ this node is permanently morphing last updated on 28 May 2023 ]

Paramdeo Singh Guyana

Generalist. Edgerunner. Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs
Search Site

Results are from Blog, Link Dumps, and #99Problems