|
|
@ -2,7 +2,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
### Instructions |
|
|
|
### Instructions |
|
|
|
|
|
|
|
|
|
|
|
- Write a function that takes a slice of integers and returns the same slice by initializing all the elements to 0. |
|
|
|
Write a function that takes a slice of integers as an argument and returns the same slice by initializing all the elements to 0. |
|
|
|
- If the slice is empty, return an empty slice. |
|
|
|
- If the slice is empty, return an empty slice. |
|
|
|
|
|
|
|
|
|
|
|
### Expected function |
|
|
|
### Expected function |
|
|
@ -15,26 +15,27 @@ func BeZero(slice []int) []int { |
|
|
|
|
|
|
|
|
|
|
|
### Usage |
|
|
|
### Usage |
|
|
|
|
|
|
|
|
|
|
|
Here is a possible program to test your function : |
|
|
|
Here is a possible program to test your function: |
|
|
|
|
|
|
|
|
|
|
|
```go |
|
|
|
```go |
|
|
|
package main |
|
|
|
package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"piscine" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
fmt.Println(BeZero([]int{1,2,3,4,5,6})) |
|
|
|
fmt.Println(piscine.BeZero([]int{1, 2, 3, 4, 5, 6})) |
|
|
|
fmt.Println(BeZero([]int{})) |
|
|
|
fmt.Println(piscine.BeZero([]int{})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
And its output : |
|
|
|
And its output: |
|
|
|
|
|
|
|
|
|
|
|
```console |
|
|
|
```console |
|
|
|
$ go run . |
|
|
|
$ go run . |
|
|
|
[0 0 0 0 0 0] |
|
|
|
[0 0 0 0 0 0] |
|
|
|
[] |
|
|
|
[] |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|