Skip to content

Commit

Permalink
feat(repeatalpha): update subject to ask for a function instead of a …
Browse files Browse the repository at this point in the history
…program

- add main.go for exam
  • Loading branch information
nprimo committed Jun 3, 2024
1 parent ef7865c commit f5aa568
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
40 changes: 29 additions & 11 deletions subjects/repeatalpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 12 additions & 0 deletions subjects/repeatalpha/main.go
Original file line number Diff line number Diff line change
@@ -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!"))
}

0 comments on commit f5aa568

Please sign in to comment.