forked from root/public
Compare commits
8 Commits
master
...
DEV-3184-n
Author | SHA1 | Date |
---|---|---|
Tiago Collot | 286a3ed0fa | 2 years ago |
Tiago Collot | 5803fdc57b | 2 years ago |
Tiago Collot | f11a0e9570 | 2 years ago |
Tiago Collot | c66e43cf03 | 2 years ago |
Tiago Collot | 819071b28b | 2 years ago |
Hamza elkhatri | 46e576c74a | 2 years ago |
Hamza elkhatri | 0b1fb869af | 2 years ago |
hamza | 7613320ce1 | 2 years ago |
1 changed files with 46 additions and 0 deletions
@ -0,0 +1,46 @@ |
|||||||
|
## concatalternate |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function `ConcatAlternate()` that receives two slices of an `int` as arguments and returns a new slice with the result of the alternated values of each slice. |
||||||
|
- The input slices can be of different lengths. |
||||||
|
- The new slice should start with an element of the largest slice. |
||||||
|
- If the slices are of equal length, the new slice should return the elements of the first slice first and then the elements of the second slice. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func ConcatAlternate(slice1,slice2 []int) []int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible program to test your function: |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"piscine" |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.ConcatAlternate([]int{1, 2, 3}, []int{4, 5, 6})) |
||||||
|
fmt.Println(piscine.ConcatAlternate([]int{2, 4, 6, 8, 10}, []int{1, 3, 5, 7, 9, 11})) |
||||||
|
fmt.Println(piscine.ConcatAlternate([]int{1, 2, 3}, []int{4, 5, 6, 7, 8, 9})) |
||||||
|
fmt.Println(piscine.ConcatAlternate([]int{1, 2, 3}, []int{})) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output: |
||||||
|
|
||||||
|
```console |
||||||
|
$ go run . |
||||||
|
[1 4 2 5 3 6] |
||||||
|
[1 2 3 4 5 6 7 8 9 10 11] |
||||||
|
[4 1 5 2 6 3 7 8 9] |
||||||
|
[1 2 3] |
||||||
|
``` |
Loading…
Reference in new issue