Last active
August 29, 2015 14:11
-
-
Save LoganathanB/8f8888b8bec3d4e18abe to your computer and use it in GitHub Desktop.
Answer for challenge #3 in http://140swift.tumblr.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@140Swift | |
let s = ["abeforth", "albus", "bagshot", "bellatrix", "black"] | |
let groupedStrings: [[String]] = { | |
var r:[[String]]=[] | |
var n = [s[0]] | |
for (i,v) in enumerate(s) { | |
if i != 0 { | |
if (String(Array(v)[0]) == String(Array(n[n.count-1])[0])) { | |
n.append(v) | |
} else { | |
r.append(n) | |
n.removeAll(keepCapacity: false) | |
n.append(v) | |
} | |
} | |
} | |
r.append(n) | |
return r | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment