2019-04-23 11:06:01 +00:00
|
|
|
## firstword
|
2019-04-18 12:50:04 +00:00
|
|
|
|
2019-04-23 11:06:01 +00:00
|
|
|
### Instructions
|
2019-04-18 12:50:04 +00:00
|
|
|
|
2024-05-29 13:46:39 +00:00
|
|
|
Write a function that takes a string and return a string containing its first word, followed by a newline (`'\n'`).
|
2019-04-18 12:50:04 +00:00
|
|
|
|
2020-06-30 09:32:21 +00:00
|
|
|
- A word is a sequence of characters delimited by spaces or by the start/end of the argument.
|
2019-04-18 12:50:04 +00:00
|
|
|
|
2024-05-29 13:46:39 +00:00
|
|
|
### Expected Function
|
2019-04-18 12:50:04 +00:00
|
|
|
|
2024-05-29 13:46:39 +00:00
|
|
|
```go
|
|
|
|
func FirstWord(s string) string {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
```
|
2019-04-18 12:50:04 +00:00
|
|
|
|
2019-06-15 07:44:37 +00:00
|
|
|
### Usage
|
2019-04-18 12:50:04 +00:00
|
|
|
|
2024-05-29 13:46:39 +00:00
|
|
|
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:
|
|
|
|
|
2019-04-18 12:50:04 +00:00
|
|
|
```console
|
2024-05-29 13:46:39 +00:00
|
|
|
$ go run .
|
2019-04-18 12:50:04 +00:00
|
|
|
hello
|
2024-05-29 13:46:39 +00:00
|
|
|
|
2019-04-18 12:50:04 +00:00
|
|
|
hello
|
2021-04-28 09:47:34 +00:00
|
|
|
$
|
2019-04-24 11:15:11 +00:00
|
|
|
```
|