Joseph Jude

Consult . Code . Coach

Swift Challenge 005: Sort comma separated words

code . swift

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(",")


Git Repository / All Swift Challenges

Got comments? Tweet it, or comment below.

Share this on: Twitter / /


comments powered by Disqus