What is a Pangram?

Lisa Jiang
2 min readApr 24, 2018

--

I stumbled upon a coding practice problem that asked me to write a function that takes a string and if it is not a pangram, it should return the missing letters.

I had no idea what a pangram was. I was not going to let that deter me. To Google I went!

A pangram is a sentence that uses all 26 letters in the alphabet. An example would be the following:

“The quick brown fox jumps over the lazy dog” contains all 26 letters in the alphabet. Don’t believe me? — count them!

Again the coding problem was asking for a function that takes a string and returns the missing letters if it is not a pangram, if it is a pangram. It will return an empty string.

Here is the much shorter implementation

Create a set of all the letters in the alphabet and a set with the letters in the given str. Use the .subtracting method to subtract the inputStrSet from the alphabetSet. Store the result in var missingLetters. Return missingLetters.

My original approach without hardcoding the alphabet was to use a for loop to iterate through Unicode Scalars range “a”…”z” initializing as Characters, turning them into strings with String.init(char). Put alphabet into a dictionary of String to Bool, letter: false

Then iterate through the given string with a for loop, every time a letter matches from the alphabet dictionary set the value of that letter to true. Iterate through the alphabet dict, if value is false, append to missingLetters. Finally return missing letters!

Thanks for reading, that’s all for today folks!

Show your support with 👏 claps below & follow me on my iOS developer journey 😊

--

--

Lisa Jiang

Software Engineer @LinkedIn| Prev: SWE Apprentice @Linkedin, Jr. iOS Dev @Fuzz, @C4Q alum | I write about my coding journey, in hopes of helping you on yours