mirror of https://github.com/01-edu/public.git
docs(firstword): require a function instead of a program
This commit is contained in:
parent
e3251487b7
commit
252325d993
|
@ -2,22 +2,44 @@
|
|||
|
||||
### Instructions
|
||||
|
||||
Write a program that takes an argument and displays its first word, followed by a newline (`'\n'`).
|
||||
Write a function that takes a string and return a string containing its first word, followed by a newline (`'\n'`).
|
||||
|
||||
- A word is a sequence of characters delimited by spaces or by the start/end of the argument.
|
||||
|
||||
- The output will be followed by a newline (`'\n'`).
|
||||
### Expected Function
|
||||
|
||||
- If the number of arguments is not 1, or if there are no words, the program displays nothing.
|
||||
```go
|
||||
func FirstWord(s string) string {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
Here is a possible way to test your function:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"piscine"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Print(piscine.FirstWord("hello there"))
|
||||
fmt.Print(piscine.FirstWord(""))
|
||||
fmt.Print(piscine.FirstWord("hello ......... bye"))
|
||||
}
|
||||
```
|
||||
|
||||
And its output:
|
||||
|
||||
```console
|
||||
$ go run . "hello there"
|
||||
hello
|
||||
$ go run . "hello ......... bye"
|
||||
hello
|
||||
$ go run .
|
||||
$ go run . "hello" "there"
|
||||
hello
|
||||
|
||||
hello
|
||||
$
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue