Skip to content

Instantly share code, notes, and snippets.

@LoganathanB
Last active August 29, 2015 14:11
Show Gist options
  • Save LoganathanB/8f8888b8bec3d4e18abe to your computer and use it in GitHub Desktop.
Save LoganathanB/8f8888b8bec3d4e18abe to your computer and use it in GitHub Desktop.
Answer for challenge #3 in http://140swift.tumblr.com
@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