Skip to content

Commit

Permalink
docs(lastword): ask for a function instead of a program
Browse files Browse the repository at this point in the history
  • Loading branch information
nprimo committed May 21, 2024
1 parent 4bd2f02 commit 8122f97
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
42 changes: 33 additions & 9 deletions subjects/lastword/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,48 @@

### Instructions

Write a program that takes a `string` and displays its last word, followed by a newline (`'\n'`).
Write a function `LastWord that takes a `string`and returns its last word followed by a`\n`.

- A word is a section of `string` delimited by spaces or by the start/end of the `string`.

- The output will be followed by a newline (`'\n'`).
### Expected function

- If the number of arguments is different from 1, or if there are no word, the program displays nothing.
```go
func LastWord(s string) string{

}
```

### Usage

Here is a possible program to test your function :

```go
package main

import (
"piscine"

"github.com/01-edu/z01"
)

func main() {
z01.PrintRune(piscine.LastWord("this ... is sparta, then again, maybe not"))
z01.PrintRune(piscine.LastWord(" "))
z01.PrintRune(piscine.LastWord(" lorem,ipsum "))
}
```

And its output :

```console
$ go run . "FOR PONY" | cat -e
PONY$
$ go run . "this ... is sparta, then again, maybe not" | cat -e
$ go run . | cat -e
not$
$ go run . " "
$ go run . "a" "b"
$ go run . " lorem,ipsum " | cat -e
$
lorem,ipsum$
$
```

### Notions

- [01-edu/z01](https://github.com/01-edu/z01)
13 changes: 13 additions & 0 deletions subjects/lastword/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"piscine"

"github.com/01-edu/z01"
)

func main() {
z01.PrintRune(piscine.LastWord("this ... is sparta, then again, maybe not"))
z01.PrintRune(piscine.LastWord(" "))
z01.PrintRune(piscine.LastWord(" lorem,ipsum "))
}

0 comments on commit 8122f97

Please sign in to comment.