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
674 B
42 lines
674 B
6 years ago
|
## Compact
|
||
6 years ago
|
|
||
6 years ago
|
### Instructions
|
||
6 years ago
|
|
||
|
Write a function that will take a pointer to a array as parameter and overwrites any element that points to `nil`.
|
||
|
|
||
6 years ago
|
- If you not sure what the function does. It exists in Ruby.
|
||
6 years ago
|
|
||
6 years ago
|
### Expected functions
|
||
6 years ago
|
|
||
|
```go
|
||
|
func Compact(ptr *[]string, length int) int {
|
||
|
|
||
|
}
|
||
|
```
|
||
6 years ago
|
|
||
6 years ago
|
### Usage
|
||
6 years ago
|
|
||
|
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$
|
||
|
```
|