07-函式‎ > ‎

07.08-問題

Problems

  • sum is a function which takes a slice of numbers and adds them together. What would its function signature look like in Go?

  • Write a function which takes an integer and halves it and returns true if it was even or false if it was odd. For example half(1) should return (0, false) and half(2) should return (1, true).

  • Write a function with one variadic parameter that finds the greatest number in a list of numbers.

  • Using makeEvenGenerator as an example, write a makeOddGenerator function that generates odd numbers.

  • The Fibonacci sequence is defined as: fib(0) = 0fib(1) = 1fib(n) = fib(n-1) + fib(n-2). Write a recursive function which can find fib(n).

  • What are defer, panic and recover? How do you recover from a run-time panic?

Comments