mirror of https://github.com/01-edu/public.git
Browse Source
* add subject for localhost * fix the name * add hints && add conditions * Update README.md * add cgi condition * add condition of http code and redirections * Update README.md * Localhost Subject * feat: Update the audir * feat: Update the audit * Add bonus part * Update README.md * add condition in bonus part * Update README.md * Update README.md * feat: subject * feat: subject * feat: subject of Printfirsthalf * feat: subject of Printfirsthalf * Update README.md * feat: subject of Printfirsthalf * Update README.md * Update README.md * Update README.md * Update README.md * Correct a Typo * Update README.md * docs(printfirsthalf): fix subject - fix exercise header - upgrade instructions - add missig import 'fmt'/'piscine' - fix console - fix white-spaces and indentation * docs(printfirsthalf): instructions upgrade * feat(go-checkpoints): add new exercise retainfirsthalf the exercise has been renamed from printfirsthalf to retain first half * docs(retainfirsthalf): directory name changed accordingly to new name --------- Co-authored-by: hamza <hamzaelkhatri@gmail.com> Co-authored-by: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Co-authored-by: Tiago Collot <collot.tiago1@gmail.com> Co-authored-by: Michele Sessa <mikysett@gmail.com>pull/2069/head
Zainab Dnaya
11 months ago
committed by
GitHub
1 changed files with 47 additions and 0 deletions
@ -0,0 +1,47 @@
|
||||
## retainfirsthalf |
||||
|
||||
### Instructions |
||||
|
||||
Write a function called `RetainFirstHalf()` that takes a `string` as an argument and returns the first half of this `string`. |
||||
|
||||
- If the length of the `string` is odd, round it down. |
||||
- If the `string` is empty, return an empty string. |
||||
- If the `string` length is equal to one, return the string. |
||||
|
||||
### Expected function |
||||
|
||||
```go |
||||
func RetainFirstHalf(str string) string { |
||||
|
||||
} |
||||
``` |
||||
|
||||
### Usage |
||||
|
||||
Here is a possible program to test your function: |
||||
|
||||
```go |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"piscine" |
||||
) |
||||
|
||||
func main() { |
||||
fmt.Println(solutions.RetainFirstHalf("This is the 1st halfThis is the 2nd half")) |
||||
fmt.Println(solutions.RetainFirstHalf("A")) |
||||
fmt.Println(solutions.RetainFirstHalf("")) |
||||
fmt.Println(solutions.RetainFirstHalf("Hello World")) |
||||
} |
||||
``` |
||||
|
||||
And its output: |
||||
|
||||
```console |
||||
$ go run . | cat -e |
||||
This is the 1st half$ |
||||
A$ |
||||
$ |
||||
Hello$ |
||||
``` |
Loading…
Reference in new issue