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.
 
 
 
 
 
 
xpetit 32eddefd09
Remove template variable [[ROOT]] from subjects and fix subjects
4 years ago
..
README.md Remove template variable [[ROOT]] from subjects and fix subjects 4 years ago

README.md

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 :

student@ubuntu:~/compact/test$ go build
student@ubuntu:~/compact/test$ ./test
a

b

c

Size after compacting: 3
a
b
c
student@ubuntu:~/compact/test$