From cf33abd9d4c98abf33409de55495531a6222ae1d Mon Sep 17 00:00:00 2001 From: Christopher Fremond Date: Fri, 21 Jun 2019 18:53:10 +0100 Subject: [PATCH 1/4] translation and fix --- subjects/compact.en.md | 8 ++++---- subjects/compact.fr.md | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/subjects/compact.en.md b/subjects/compact.en.md index 4f35ffe77..576dec077 100644 --- a/subjects/compact.en.md +++ b/subjects/compact.en.md @@ -1,12 +1,12 @@ -## Compact +## compact ### Instructions -Write a function that will take a pointer to a array as parameter and overwrites any element that points to `nil`. +Write a function `Compact` that takes a pointer to an array as parameter and overwrites any element that points to `nil`. -- If you not sure what the function does. It exists in Ruby. +- Hint: This fonction exists in Ruby. -### Expected functions +### Expected function ```go func Compact(ptr *[]string, length int) int { diff --git a/subjects/compact.fr.md b/subjects/compact.fr.md index 4f35ffe77..b2a50fc8a 100644 --- a/subjects/compact.fr.md +++ b/subjects/compact.fr.md @@ -1,12 +1,12 @@ -## Compact +## compact ### Instructions -Write a function that will take a pointer to a array as parameter and overwrites any element that points to `nil`. +Écrire une fonction `Compact` qui prend un pointeur sur tableau comme paramètre et qui réécris sur les éléments qui pointent sur `nil`. -- If you not sure what the function does. It exists in Ruby. +- Indice: Cette fonction existe in Ruby. -### Expected functions +### Fonction attendue ```go func Compact(ptr *[]string, length int) int { @@ -14,9 +14,9 @@ func Compact(ptr *[]string, length int) int { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -31,7 +31,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/test$ go build From 0257465db7fe3ad8bdea7998df87faf161d3cc1c Mon Sep 17 00:00:00 2001 From: Christopher Fremond Date: Fri, 21 Jun 2019 18:54:32 +0100 Subject: [PATCH 2/4] adjustment --- subjects/compact.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/compact.en.md b/subjects/compact.en.md index 576dec077..3c82da604 100644 --- a/subjects/compact.en.md +++ b/subjects/compact.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function `Compact` that takes a pointer to an array as parameter and overwrites any element that points to `nil`. +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. From 103d9d6245cce0d468d7f950e480ead3d483b6f6 Mon Sep 17 00:00:00 2001 From: Christopher Fremond Date: Fri, 21 Jun 2019 19:02:55 +0100 Subject: [PATCH 3/4] cpmpact modif --- subjects/compact.en.md | 2 +- subjects/compact.fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subjects/compact.en.md b/subjects/compact.en.md index 3c82da604..29184b971 100644 --- a/subjects/compact.en.md +++ b/subjects/compact.en.md @@ -4,7 +4,7 @@ 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. +- Hint : This fonction exists in Ruby. ### Expected function diff --git a/subjects/compact.fr.md b/subjects/compact.fr.md index b2a50fc8a..ed9c3efb6 100644 --- a/subjects/compact.fr.md +++ b/subjects/compact.fr.md @@ -4,7 +4,7 @@ Écrire une fonction `Compact` qui prend un pointeur sur tableau comme paramètre et qui réécris sur les éléments qui pointent sur `nil`. -- Indice: Cette fonction existe in Ruby. +- Indice : Cette fonction existe in Ruby. ### Fonction attendue From 79e6a7709b03b44c763d4a29a8e2991ab64e739f Mon Sep 17 00:00:00 2001 From: Christopher Fremond Date: Fri, 21 Jun 2019 19:12:40 +0100 Subject: [PATCH 4/4] fix of compact --- subjects/compact.en.md | 48 +++++++++++++++++++++++++++++++++--------- subjects/compact.fr.md | 44 +++++++++++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 18 deletions(-) diff --git a/subjects/compact.en.md b/subjects/compact.en.md index 29184b971..5c637f851 100644 --- a/subjects/compact.en.md +++ b/subjects/compact.en.md @@ -1,15 +1,18 @@ -## compact +## Compact ### Instructions -Write a function `Compact` that takes a pointer to an array as parameter and overwrites the elements that points to `nil`. +Write a function `Compact` that takes a pointer to a slice of strings as the argument. +This function must: -- Hint : This fonction exists in Ruby. +- Return the number of elements with non-`nil`. -### Expected function +- Compact, i.e., delete the elements with `nil` in the slice. + +### Expected functions ```go -func Compact(ptr *[]string, length int) int { +func Compact(ptr *[]string) int { } ``` @@ -21,13 +24,29 @@ Here is a possible [program](TODO-LINK) to test your function : ```go package main -import fmt +import ( + "fmt" + + piscine ".." +) + +const N = 6 func main() { - array := []string{"hello", " ", "there", " ", "bye"} + arr := make([]string, N) + arr[0] = "a" + arr[2] = "b" + arr[4] = "c" + + for _, v := range arr { + fmt.Println(v) + } - ptr := &array - fmt.Println(Compact(ptr, len(array))) + fmt.Println("Size after compacting:", piscine.Compact(&arr)) + + for _, v := range arr { + fmt.Println(v) + } } ``` @@ -36,6 +55,15 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -3 +a + +b + +c + +Size after compacting: 3 +a +b +c student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/compact.fr.md b/subjects/compact.fr.md index ed9c3efb6..aaeb5b8e3 100644 --- a/subjects/compact.fr.md +++ b/subjects/compact.fr.md @@ -2,14 +2,17 @@ ### Instructions -Écrire une fonction `Compact` qui prend un pointeur sur tableau comme paramètre et qui réécris sur les éléments qui pointent sur `nil`. +Écrire une fonction `Compact` qui prend un pointeur sur slice de `strings` comme paramètre. +Cette fonction doit: -- Indice : Cette fonction existe in Ruby. +- Retourner le nombre d'éléments avec des valeurs non-`nil` + +- Comprimer, c.à.d., effacer les éléments qui ont une valeur `nil` dans la slice. ### Fonction attendue ```go -func Compact(ptr *[]string, length int) int { +func Compact(ptr *[]string) int { } ``` @@ -21,13 +24,29 @@ Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main -import fmt +import ( + "fmt" + + piscine ".." +) + +const N = 6 func main() { - array := []string{"hello", " ", "there", " ", "bye"} + arr := make([]string, N) + arr[0] = "a" + arr[2] = "b" + arr[4] = "c" + + for _, v := range arr { + fmt.Println(v) + } - ptr := &array - fmt.Println(Compact(ptr, len(array))) + fmt.Println("Size after compacting:", piscine.Compact(&arr)) + + for _, v := range arr { + fmt.Println(v) + } } ``` @@ -36,6 +55,15 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -3 +a + +b + +c + +Size after compacting: 3 +a +b +c student@ubuntu:~/piscine/test$ ```