From f5aa56821acf89fd6c71b0517064ea48b9aa3830 Mon Sep 17 00:00:00 2001 From: nprimo Date: Mon, 3 Jun 2024 12:15:48 +0100 Subject: [PATCH] feat(repeatalpha): update subject to ask for a function instead of a program - add main.go for exam --- subjects/repeatalpha/README.md | 40 ++++++++++++++++++++++++---------- subjects/repeatalpha/main.go | 12 ++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 subjects/repeatalpha/main.go diff --git a/subjects/repeatalpha/README.md b/subjects/repeatalpha/README.md index 9fcaa3e160..881fea477d 100644 --- a/subjects/repeatalpha/README.md +++ b/subjects/repeatalpha/README.md @@ -2,25 +2,43 @@ ### Instructions -Write a program called `repeat_alpha` that takes a `string` and displays it repeating each alphabetical character as many times as its alphabetical index. - -The result must be followed by a newline (`'\n'`). +Write a function called `RepeatAlpha` that takes a `string` and displays it repeating each alphabetical character as many times as its alphabetical index. `'a'` becomes `'a'`, `'b'` becomes `'bb'`, `'e'` becomes `'eeeee'`, etc... -If the number of arguments is different from 1, the program displays nothing. +### Expected Function + +```go +func RepeatAlpha(s string) string { +} +``` ### Usage +Here is a possible program to test your function: + +```go +package main + +import ( + "fmt" +) + +func main() { + fmt.Println(RepeatAlpha("abc")) + fmt.Println(RepeatAlpha("Choumi.")) + fmt.Println(RepeatAlpha("")) + fmt.Println(RepeatAlpha("abacadaba 01!")) +} +``` + +And its output: + ```console -$ go run . abc | cat -e -abbccc -$ go run . Choumi. | cat -e +$ go run . | cat -e +abbccc$ CCChhhhhhhhooooooooooooooouuuuuuuuuuuuuuuuuuuuummmmmmmmmmmmmiiiiiiiii.$ -$ go run . "abacadaba 01!" | cat -e -abbacccaddddabba 01!$ -$ go run . -$ go run . "" | cat -e $ +abbacccaddddabba 01!$ $ ``` diff --git a/subjects/repeatalpha/main.go b/subjects/repeatalpha/main.go new file mode 100644 index 0000000000..e8ae0c12d8 --- /dev/null +++ b/subjects/repeatalpha/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println(RepeatAlpha("abc")) + fmt.Println(RepeatAlpha("Choumi.")) + fmt.Println(RepeatAlpha("")) + fmt.Println(RepeatAlpha("abacadaba 01!")) +}