Browse Source

docs(swapfirst): fix subject

- fix exercise title
- upgrade instructions
- add missing import 'piscine'
- fix white-spaces and indentation
pull/2069/head
Tiago Collot 2 years ago committed by Michele
parent
commit
b97ff1feff
  1. 20
      subjects/swapfirst/README.md

20
subjects/swapfirst/README.md

@ -1,8 +1,9 @@
## swap-first
## swapfirst
### Instructions
- Write a function that takes a slice in parameter and swaps the two first element then return the new value
Write a function that takes a slice of integers as an argument and returns another slice of integers with the two first elements swapped.
- If the slice contains less than two elements return the same slice.
### Expected function
@ -15,27 +16,28 @@ func SwapFirst(slice []int) []int {
### Usage
Here is a possible program to test your function :
Here is a possible program to test your function:
```go
package main
import (
"fmt"
"piscine"
)
func main() {
fmt.Println(SwapFirst([]int{1,2,3,4}))
fmt.Println(SwapFirst([]int{3,4}))
fmt.Println(SwapFirst([]int{1}))
fmt.Println(piscine.SwapFirst([]int{1, 2, 3, 4}))
fmt.Println(piscine.SwapFirst([]int{3, 4, 6}))
fmt.Println(piscine.SwapFirst([]int{1}))
}
```
And its output :
And its output:
```console
$ go run .
[2,1,3,4]
[4,3]
[2 1 3 4]
[4 3 6]
[1]
```

Loading…
Cancel
Save