Created
August 13, 2014 15:46
-
-
Save peterstuart/b520c368b9b955bbf320 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
let evenNumbersAsString = numbers | |
.filter { $0 % 2 == 0 } | |
.map { NSNumberFormatter.localizedStringFromNumber($0, numberStyle: .DecimalStyle) } | |
.reduce("") { countElements($0) == 0 ? $1 : $0 + "\n" + $1 } | |
// "10,000\n50,000\n100,000\n1,000,000" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this is really help me a lot!
Which I was concern how to add the condition into reduce function.