Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Last active May 26, 2019 13:16
Show Gist options
  • Save AppleCEO/1be7054dc60e5a6a613247ee259a74ae to your computer and use it in GitHub Desktop.
Save AppleCEO/1be7054dc60e5a6a613247ee259a74ae to your computer and use it in GitHub Desktop.
let someNumbers = [10, 8, 7, 1, 9]
// 초깃값이 0이고 someNumbers 내부의 모든 값을 더합니다.
let sum: Int = someNumbers.reduce(0, { (first: Int, second: Int) -> Int in
//print("\(first) + \(second)") //어떻게 동작하는지 확인해보세요
return first + second
})
// 35
// 초깃값이 5이고 someNumbers 내부의 모든 값을 뺍니다.
var subtract: Int = someNumbers.reduce(5, { (first: Int, second: Int) -> Int in
//print("\(first) - \(second)") //어떻게 동작하는지 확인해보세요
return first - second
})
// -30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment