mirror of https://github.com/01-edu/public.git
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.
42 lines
606 B
42 lines
606 B
2 years ago
|
## secondhalf
|
||
2 years ago
|
|
||
|
### Instructions
|
||
|
|
||
2 years ago
|
Write a function `SecondHalf()` that receives a slice of `int` and returns another slice of `int` with the last half of the values.
|
||
|
|
||
|
- If the length is odd, round it down.
|
||
2 years ago
|
|
||
|
### Expected function
|
||
|
|
||
|
```go
|
||
2 years ago
|
func SecondHalf(slice []int) []int {
|
||
2 years ago
|
|
||
|
}
|
||
|
```
|
||
|
|
||
|
### Usage
|
||
|
|
||
2 years ago
|
Here is a possible program to test your function:
|
||
2 years ago
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
2 years ago
|
"piscine"
|
||
2 years ago
|
)
|
||
|
|
||
|
func main() {
|
||
2 years ago
|
fmt.Println(piscine.SecondHalf([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}))
|
||
|
fmt.Println(piscine.SecondHalf([]int{1, 2, 3}))
|
||
2 years ago
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
And its output:
|
||
2 years ago
|
|
||
|
```console
|
||
2 years ago
|
$ go run . | cat -e
|
||
|
[5 6 7 8 9 10]
|
||
|
[2 3]
|
||
|
```
|