Skip to content

Instantly share code, notes, and snippets.

@suraphanL
Last active September 10, 2016 20:03
Show Gist options
  • Save suraphanL/5a912377eac9182ceb4b02de418cced9 to your computer and use it in GitHub Desktop.
Save suraphanL/5a912377eac9182ceb4b02de418cced9 to your computer and use it in GitHub Desktop.
var total = 0
for num in intArray {
total = total + num
}
let totalByReduce = intArray.reduce(0) { total, num in total + num }
let totalByReduceShortHand = intArray.reduce(0, combine: { $0 + $1 })
let shortReduce = intArray.reduce(0, combine: +)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment