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.
|
|
|
## compact
|
|
|
|
|
|
|
|
### Instructions
|
|
|
|
|
|
|
|
Write a function `Compact` that takes a pointer to an array as parameter and overwrites the elements that points to `nil`.
|
|
|
|
|
|
|
|
- Hint : This fonction exists in Ruby.
|
|
|
|
|
|
|
|
### Expected function
|
|
|
|
|
|
|
|
```go
|
|
|
|
func Compact(ptr *[]string, length int) int {
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
|
|
|
Here is a possible [program](TODO-LINK) to test your function :
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import fmt
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
array := []string{"hello", " ", "there", " ", "bye"}
|
|
|
|
|
|
|
|
ptr := &array
|
|
|
|
fmt.Println(Compact(ptr, len(array)))
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
And its output :
|
|
|
|
|
|
|
|
```console
|
|
|
|
student@ubuntu:~/piscine/test$ go build
|
|
|
|
student@ubuntu:~/piscine/test$ ./test
|
|
|
|
3
|
|
|
|
student@ubuntu:~/piscine/test$
|
|
|
|
```
|