Browse Source

feat(repeatalpha): update subject to ask for a function instead of a program

- add main.go for exam
pull/2619/head
nprimo 4 months ago committed by Harry
parent
commit
731e2ff90b
  1. 40
      subjects/repeatalpha/README.md
  2. 12
      subjects/repeatalpha/main.go

40
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!$
$
```

12
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!"))
}
Loading…
Cancel
Save