Skip to content

Instantly share code, notes, and snippets.

@ambientlight
Last active February 2, 2020 12:09
Show Gist options
  • Save ambientlight/466d28eff77c1b419a3244a668529a90 to your computer and use it in GitHub Desktop.
Save ambientlight/466d28eff77c1b419a3244a668529a90 to your computer and use it in GitHub Desktop.
Sum with a reduce
let nums = [1, 2, 3, 6, 16, 4]
let reducer: (Int, Int) -> Int = { (sum, increment) in
sum + increment
}
let sum = nums.reduce(0, reducer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment