mirror of https://github.com/01-edu/public.git
feat(repeatalpha): update subject to ask for a function instead of a program
- add main.go for exam
This commit is contained in:
parent
73b2126140
commit
731e2ff90b
|
@ -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!$
|
||||
$
|
||||
```
|
||||
|
|
|
@ -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!"))
|
||||
}
|
Loading…
Reference in New Issue