Browse Source

DEV-3379-new-go-exercise-swap-last (#1368)

* DEV-3379 add subject swapLast

* rename the title

* docs(swaplast): fix subject

- upgrade instructions
- add missing import 'piscine'
- fix expected output
- fix white-spaces and indentation

* docs(swaplast): fix typo

---------

Co-authored-by: Tiago Collot <collot.tiago1@gmail.com>
Co-authored-by: Michele Sessa <mikysett@gmail.com>
pull/1513/head
Hamza elkhatri 12 months ago committed by GitHub
parent
commit
32c18ebf60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 44
      subjects/swaplast/README.md

44
subjects/swaplast/README.md

@ -0,0 +1,44 @@
## swaplast
### Instructions
Write a function that takes as an argument a slice of integers and return another slice of integers with the last two elements swapped.
> If the slice contains less than two elements return the same slice.
### Expected function
```go
func SwapLast(slice []int) []int {
}
```
### Usage
Here is a possible program to test your function:
```go
package main
import (
"fmt"
"piscine"
)
func main() {
fmt.Println(piscine.SwapLast([]int{1, 2, 3, 4}))
fmt.Println(piscine.SwapLast([]int{3, 4, 5}))
fmt.Println(piscine.SwapLast([]int{1}))
}
```
And its output:
```console
$ go run .
[1 2 4 3]
[3 5 4]
[1]
```
Loading…
Cancel
Save