Last active
May 26, 2019 13:16
-
-
Save AppleCEO/1be7054dc60e5a6a613247ee259a74ae to your computer and use it in GitHub Desktop.
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
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