Skip to content

Instantly share code, notes, and snippets.

@gallaugher
Last active June 27, 2018 02:59
Show Gist options
  • Select an option

  • Save gallaugher/3fc4c36f0a528ed40e51b186f522fb6f to your computer and use it in GitHub Desktop.

Select an option

Save gallaugher/3fc4c36f0a528ed40e51b186f522fb6f to your computer and use it in GitHub Desktop.
full syntax of .reduce used to total an array of Int
// go through all eleemnts of .scores
// 0 is the initial accumulating value (e.g. start at zero)
// x is the current accumulating value
// y is the next accumulating value
let total = scores.reduce(0, {x, y in
return x + y
})
let average = Double(total) / Double(scores.count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment