You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
645 B

## 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
2 years ago
func SumArray(numbers []int) int {
// your code here
}
```
### Usage
2 years ago
Here is a possible program to test your function:
```go
package main
import (
"fmt"
)
func main(){
2 years ago
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}))
}
```
and the output should be:
```console
$ go run .
15
0
-15
3
2 years ago
```