Challenge: Write a program that takes a comma separated sequence of words and prints the words in a comma-separated sequence after sorting them alphabetically. Suppose the following input is supplied to the program: without,hello,bag,world. Then, the output should be: bag,hello,without,world
Logic: Separate the words and then sort them
import Foundation let ar = "without,hello,bag,world" let br = ar.componentsSeparatedByString(",") print(br.sort())
- string separation
- array sorting
Git Repository / All Swift Challenges
Got comments? Tweet it, or comment below.