public/subjects/fromto/README.md

49 lines
932 B
Markdown
Raw Permalink Normal View History

## fromto
2022-07-27 18:13:34 +00:00
### Instructions
2023-06-19 16:08:39 +00:00
Write a function that takes two `integers` and returns a `string` showing the range of numbers from the first to the second.
2022-07-27 18:33:40 +00:00
2023-06-19 16:08:39 +00:00
- The numbers must be separated by a comma and a space.
- If any of the arguments is bigger than `99` or less than `0`, the function returns `Invalid` followed by a newline `\n`.
- Prepend a `0` to any number that is less than `10`.
- Add a new line `\n` at the end of the `string`.
2022-07-27 18:13:34 +00:00
### Expected function
2022-07-27 18:33:40 +00:00
2022-07-27 18:13:34 +00:00
```go
func FromTo(from int, to int) string {
}
```
### Usage
2022-09-21 13:53:49 +00:00
Here is a possible program to test your function:
2022-07-27 18:13:34 +00:00
```go
package main
import (
"fmt"
"psicine"
)
2022-07-27 18:13:34 +00:00
func main() {
fmt.Print(piscine.FromTo(1, 10))
fmt.Print(piscine.FromTo(10, 1))
fmt.Print(piscine.FromTo(10, 10))
fmt.Print(piscine.FromTo(100, 10))
2022-07-27 18:13:34 +00:00
}
```
2023-06-19 16:08:39 +00:00
2022-09-21 13:53:49 +00:00
And its output:
2022-07-27 18:13:34 +00:00
```console
$ go run . | cat -e
01, 02, 03, 04, 05, 06, 07, 08, 09, 10$
10, 09, 08, 07, 06, 05, 04, 03, 02, 01$
10$
Invalid$
2022-07-27 18:13:34 +00:00
```