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 nums = [1,2,3,4,5,6,7,8,9,10] | |
let total = nums.reduce(1, *) | |
print(total) // 3628800になる |
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 nums = [1,2,3,4,5,6,7,8,9,10] | |
let total = nums.reduce(0, +) | |
print(total) // 55になる |
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 add: (Int, Int) -> Int = (+) |
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 nums = [1,2,3,4,5,6,7,8,9,10] | |
let calculator: (Int, Int) -> Int = { currentTotal, num in | |
let newTotal = currentTotal + num | |
return newTotal | |
} | |
//let add: (Int, Int) -> Int = (+) | |
let total = nums.reduce(0, calculator) |
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 nums = [1,2,3,4,5,6,7,8,9,10] | |
let total | |
= nums.reduce(0, { currentTotal, num in | |
let newTotal = currentTotal + num | |
return newTotal | |
}) | |
print(total) // 55になる |
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 配列 = [1,2,3,4,5,6,7,8,9,10] | |
let パックマンの初期値 = 0 | |
let 最終的なパックマンの値 | |
= 配列.reduce(パックマンの初期値, { パックマンの現在値, 配列から1個取り出した値 in | |
// パックマンに配列の要素を1つ食わせるたびに以下の処理が実行される | |
let 新たなパックマンの値 = パックマンの現在値 + 配列から1個取り出した値 | |
return 新たなパックマンの値 | |
}) |
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 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
let total = nums.reduce(0, +) | |
print(total) |
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 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
var total = 0 | |
for num in nums { | |
total += num | |
} | |
print(total) |
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
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
if let indexPath = tableView.indexPathForSelectedRow { | |
tableView.deselectRow(at: indexPath, animated: true) | |
} | |
} |
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
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
tableView.deselectRow(at: indexPath, animated: true) | |
performSegue(withIdentifier: "ShowList2", sender: nil) | |
} |