forked from root/public
Browse Source
- format exercise title - upgrade instructions - fix white-spaces and indentation - add missing import 'piscine'DEV-3184-new-go-exercise-concatalternate
![collot.tiago1@gmail.com](/git/assets/img/avatar_default.png)
1 changed files with 17 additions and 15 deletions
@ -1,45 +1,47 @@ |
|||||||
## Concat-Alternate |
## concatalternate |
||||||
|
|
||||||
|
|
||||||
### Instructions |
### Instructions |
||||||
|
|
||||||
Write a function that receives two slices of int as arguments and returns a new one with the result of alternating the values of each. |
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 may be of different lengths. |
- The input slices can be of different lengths. |
||||||
- The new slice should contain the elements of the larger slice first and then the elements of the smaller slice. |
- The new slice should return the elements of the larger slice first and then the elements of the smaller slice. |
||||||
- If the slices are of equal length, the new slice should contain the elements of the first slice first and then the elements of the second 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. |
||||||
- The new slice should be in the same order as the input slices. |
- The new slice should be in the same order as the input slices. |
||||||
|
|
||||||
### Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func ConcatAlternate(slice1,slice2 []int) []int { |
func ConcatAlternate(slice1,slice2 []int) []int { |
||||||
|
|
||||||
} |
} |
||||||
``` |
``` |
||||||
|
|
||||||
### Usage |
### Usage |
||||||
|
|
||||||
Here is a possible program to test your function : |
Here is a possible program to test your function: |
||||||
|
|
||||||
```go |
```go |
||||||
package main |
package main |
||||||
|
|
||||||
import ( |
import ( |
||||||
"fmt" |
"fmt" |
||||||
|
"piscine" |
||||||
) |
) |
||||||
|
|
||||||
func main() { |
func main() { |
||||||
fmt.Println(ConcatAlternate([]int{1,2,3},[]int{4,5,6})) |
fmt.Println(piscine.ConcatAlternate([]int{1, 2, 3}, []int{4, 5, 6})) |
||||||
fmt.Println(ConcatAlternate([]int{1,2,3},[]int{4,5,6,7,8,9})) |
fmt.Println(piscine.ConcatAlternate([]int{1, 3, 5, 7, 9}, []int{2, 4, 6, 8, 10})) |
||||||
fmt.Println(ConcatAlternate([]int{1,2,3},[]int{})) |
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 : |
And its output: |
||||||
|
|
||||||
```console |
```console |
||||||
$ go run . |
$ go run . |
||||||
[1, 4, 2, 5, 3, 6] |
[1 4 2 5 3 6] |
||||||
[1, 4, 2, 5, 3, 6, 7, 8, 9] |
[1 2 3 4 5 6 7 8 9 10] |
||||||
[1, 2, 3] |
[4 1 5 2 6 3 7 8 9] |
||||||
|
[1 2 3] |
||||||
``` |
``` |
||||||
|
Loading…
Reference in new issue