Created
January 24, 2017 03:50
-
-
Save leodabus/6ef6dba41c461c69dd12159e2a519d4c to your computer and use it in GitHub Desktop.
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
extension BidirectionalCollection where Iterator.Element == String, SubSequence.Iterator.Element == String { | |
var sentence: String { | |
guard let last = last else { return "" } | |
return count <= 2 ? joined(separator: " and ") : | |
dropLast().joined(separator: ", ") + " and " + last | |
} | |
} |
Author
leodabus
commented
Jan 24, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment