Joseph Jude

Consult . Code . Coach

swift Challenge 008: Check if a string is a pangram


code . swift

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.


Like the post? Retweet it. Got comments? Reply.

swift Challenge 008: Check if a string is a pangram by @jjude: https://t.co/S7lMiU7h8t

— Joseph Jude (@jjude) December 8, 2016
Share this on: Twitter / /

Comments

comments powered by Disqus