Skip to content

Instantly share code, notes, and snippets.

@peterstuart
Created August 13, 2014 15:46
Show Gist options
  • Save peterstuart/b520c368b9b955bbf320 to your computer and use it in GitHub Desktop.
Save peterstuart/b520c368b9b955bbf320 to your computer and use it in GitHub Desktop.
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"
@oaleeapp
Copy link

Thanks, this is really help me a lot!

Which I was concern how to add the condition into reduce function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment