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.
 
 
 
 
 
 
Augusto 7d693b518b Add link to the explanation of `zero values` in go` 3 years ago
..
README.md Add link to the explanation of `zero values` in go` 3 years ago

README.md

Compact

Instructions

Write a function Compact that takes a pointer to a slice of strings 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
$