//: Playground - noun: a place where people can play
import UIKit
_ = "Hello, playground" //I'm not used
func calculator (a: Int, b: Int, _ operation: (Int, Int) -> Int) -> Int {
return operation(a,b)
}
// all examples = 6
let example1 = calculator(a: 2, b: 3) { (a: Int, b: Int) -> Int in
return a * b
}
let example2 = calculator(a: 2, b: 3, { (a, b) in
return a * b
})
let example3 = calculator(a: 2, b: 3, { (a, b) in
a * b
})
let example4 = calculator(a: 2, b: 3) { $0 * $1 }
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.