Complete the code to call the recursive function correctly.
func factorial(n int) int {
if n == 0 {
return 1
}
return n * factorial([1])
}The factorial function calls itself with n-1 to reduce the problem size step by step.
Complete the code to check the base case in recursion.
func sumToN(n int) int {
if [1] {
return 0
}
return n + sumToN(n-1)
}The base case stops recursion when n is zero or less, returning 0.
Fix the error in the recursive Fibonacci function call.
func fibonacci(n int) int {
if n <= 1 {
return n
}
return fibonacci([1]) + fibonacci(n-2)
}The Fibonacci function calls itself with n-1 and n-2 to sum previous two numbers.
Fill both blanks to create a recursive function that prints numbers from n down to 1.
func printDown(n int) {
if n [1] 0 {
return
}
fmt.Println(n)
printDown([2])
}The function stops when n is less or equal to 0 and calls itself with n-1 to count down.
Fill all three blanks to create a recursive function that computes the sum of elements in a slice.
func sumSlice(nums []int) int {
if len(nums) [1] 0 {
return 0
}
return nums[0] + sumSlice(nums[[2]:[3]])
}The base case checks if slice length is zero. The recursive call sums first element plus sum of the rest slice from index 1 to end.
