Created
February 2, 2020 12:03
-
-
Save ambientlight/aba00f202038ccd1e86c1542302a2f6d to your computer and use it in GitHub Desktop.
Loop with a sum
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 nums = [1, 2, 3, 6, 16, 4] | |
let accumulator: (Int, Int) -> Int = { (sum, increment) in | |
sum + increment | |
} | |
var sum = 0 | |
for var i in (0..<nums.count) { | |
sum = accumulator(sum, nums[i]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment