Joseph Jude

swift Challenge 008: Check if a string is a pangram

2016.01.03 / code / swift /

Write a program to check if the string entered by the user is a pangrams. Pangrams are sentences constructed by using every letter of the alphabet at least once.

Challenge: Write a program to check if the string entered by the user is a pangrams. Pangrams are sentences constructed by using every letter of the alphabet at least once. Ex: 'The quick brown fox jumps over the lazy dog'

Logic:

Code:


func isPangram(phrase: String) -> Bool {
  let alphabet = "abcdefghijklmnopqrstuvwxyz"
  let (alphabetSet, phraseSet) = (Set(alphabet.characters), Set(phrase.lowercaseString.characters))
  let resultSet = alphabetSet.subtract(phraseSet)
  return resultSet.count == 0 ? true : false
}

var phrase = readLine()!
print(isPangram(phrase))

Git Repository / All Swift Challenges

Got comments? Tweet it, or comment below.


Share this post on

Twitter | | |
Sign up for my weekly newsletter

I will send blog updates to this email. You can unsubscribe at any time using the link in those emails.