Created
March 29, 2016 05:27
-
-
Save takasek/c364c9c12cf1910f4911 to your computer and use it in GitHub Desktop.
高階関数で植木算、どうしたらエレガントに書けるかな。[10,10,10]にマージン1を足して32を出力したい。enumerateしてindexを見て分岐? #CodePiece
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 a: Int = [10,10,10] | |
.enumerate() | |
.reduce(0) { (sum: Int, item: (index: Int, value: Int)) in | |
sum + item.value + (item.index == 0 ? 0 : 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment