Complete the code to create a closure that adds two numbers.
let add = { (a: Int, b: Int) -> Int in return a [1] b }The closure adds two integers using the + operator.
Complete the code to call the closure with arguments 3 and 5.
let result = add([1], 5)
The closure is called with 3 and 5 as arguments, so the first argument is 3.
Fix the error in the closure syntax to correctly multiply two numbers.
let multiply = { (a: Int, b: Int) -> Int [1] a * b }The keyword 'in' separates the closure parameters and return type from the body.
Fill both blanks to create a closure that returns the square of a number.
let square = { (num: Int) [1] num [2] num }The closure uses 'in' to separate parameters from the body and '*' to multiply the number by itself.
Fill all three blanks to create a closure that filters even numbers from an array.
let evens = numbers.filter { [1] in [2] % 2 [3] 0 }The closure takes 'num' as input, then checks if 'num % 2 == 0' to filter even numbers.
