2022-06-14 12:18:38 +00:00
|
|
|
## array-sum
|
|
|
|
|
|
|
|
### Instructions
|
|
|
|
|
|
|
|
Write a function that takes an array of numbers and returns the sum of all the numbers in the array.
|
|
|
|
- If the array is empty, the function should return 0.
|
|
|
|
|
|
|
|
### Expected function
|
|
|
|
|
|
|
|
```go
|
2022-06-15 12:09:32 +00:00
|
|
|
func SumArray(numbers []int) int {
|
2022-06-14 12:18:38 +00:00
|
|
|
// your code here
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
2022-06-21 00:36:37 +00:00
|
|
|
Here is a possible program to test your function:
|
|
|
|
|
2022-06-14 12:18:38 +00:00
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main(){
|
2022-06-15 12:09:32 +00:00
|
|
|
fmt.Println(SumArray([]int{1,2,3,4,5}))
|
|
|
|
fmt.Println(SumArray([]int{}))
|
|
|
|
fmt.Println(SumArray([]int{-1,-2,-3,-4,-5}))
|
|
|
|
fmt.Println(SumArray([]int{-1,2,3,4,-5}))
|
2022-06-14 12:18:38 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
and the output should be:
|
|
|
|
|
|
|
|
```console
|
|
|
|
$ go run .
|
|
|
|
15
|
|
|
|
0
|
|
|
|
-15
|
|
|
|
3
|
2022-06-15 12:09:32 +00:00
|
|
|
```
|