Created
April 25, 2016 09:26
-
-
Save jhugman/d3a5b26abe03fd4be53045d6aa354771 to your computer and use it in GitHub Desktop.
Schwartzian Transform in Swift.
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
let strings = ["Peter Venkman", "Raymond Stantz", "Egon Spengler", "Dana Barrett", "Louis Tully"] | |
let sortedBySurname = | |
strings.map { ["string": $0, "surname": $0.componentsSeparatedByString(" ").last! ] } | |
.sort { $0["surname"]!.caseInsensitiveCompare($1["surname"]!) == .OrderedAscending } | |
.map { $0["string"]! } | |
// https://en.wikipedia.org/wiki/Schwartzian_transform |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment