Last active
June 27, 2018 02:59
-
-
Save gallaugher/3fc4c36f0a528ed40e51b186f522fb6f to your computer and use it in GitHub Desktop.
full syntax of .reduce used to total an array of Int
This file contains hidden or 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
| // 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