mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
650 B
39 lines
650 B
2 years ago
|
## addfront
|
||
2 years ago
|
|
||
|
### Instructions
|
||
|
|
||
2 years ago
|
Write a function that takes a string and a slice of strings, this function will return a new slice of sting with the given string prepended
|
||
2 years ago
|
|
||
|
### Expected function
|
||
|
|
||
|
```go
|
||
2 years ago
|
func AddFront(s string, slice []string) []string {
|
||
2 years ago
|
// your code here
|
||
|
}
|
||
|
```
|
||
|
|
||
|
### Usage
|
||
|
|
||
|
Here is a possible program to test your function:
|
||
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
func main() {
|
||
2 years ago
|
fmt.Println(AddFront("Hello", []string{"world"}))
|
||
2 years ago
|
fmt.Println(AddFront("Hello", []string{"world", "!"}))
|
||
2 years ago
|
fmt.Println(AddFront("Hello", []string{}))
|
||
2 years ago
|
}
|
||
|
```
|
||
|
|
||
|
and the output should be:
|
||
|
|
||
|
```console
|
||
|
$ go run .
|
||
|
[Hello world]
|
||
|
[Hello world !]
|
||
|
[Hello]
|
||
2 years ago
|
```
|