mirror of https://github.com/01-edu/public.git
Browse Source
* 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
1 changed files with 44 additions and 0 deletions
@ -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…
Reference in new issue