Complete the code to define a nested function inside the outer function.
func outer() {
func [1]() {
print("Hello from inner")
}
inner()
}The nested function inside outer() is named inner. This name is used to define and call it.
Complete the code to return the result of the nested function.
func outer() -> Int {
func [1]() -> Int {
return 5
}
return inner()
}The nested function inner() returns an integer, and outer() returns the result of calling inner().
Fix the error in the nested function call by completing the blank.
func outer() {
func inner() {
print("Inside inner")
}
[1]()
}The nested function inner() must be called by its name inside outer().
Fill both blanks to create a nested function that adds two numbers and returns the sum.
func addNumbers(a: Int, b: Int) -> Int {
func [1]() -> Int {
return a [2] b
}
return sum()
}- or *.The nested function is named sum and returns the addition of a and b using the + operator.
Fill all three blanks to create a nested function that multiplies a number by itself and returns the result.
func calculateSquare(number: Int) -> Int {
func [1]() -> Int {
return number [2] number
}
return [3]()
}The nested function is named square, multiplies number by itself using *, and is called by square().