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.
777 B
777 B
Compact
Instructions
Write a function Compact
that takes a pointer to a slice of string
as the argument.
This function must:
-
Return the number of elements with non-zero value.
-
Compact, i.e., delete the elements with zero-values in the slice.
Expected functions
func Compact(ptr *[]string) int {
}
Usage
Here is a possible program to test your function :
package main
import (
"fmt"
"piscine"
)
const N = 6
func main() {
a := make([]string, N)
a[0] = "a"
a[2] = "b"
a[4] = "c"
for _, v := range a {
fmt.Println(v)
}
fmt.Println("Size after compacting:", piscine.Compact(&a))
for _, v := range a {
fmt.Println(v)
}
}
And its output :
$ go run .
a
b
c
Size after compacting: 3
a
b
c
$