Approach : Using append function and spread (…)
operator
append(slice1,
slice2...)
App.go
package main import ( "fmt" ) func main() { evenNumbers := []int{2, 4, 6, 8} oddNumbers := []int{1, 3, 5, 7} result := append(evenNumbers, oddNumbers...) fmt.Println(result) }
Output
[2 4 6 8 1
3 5 7]
No comments:
Post a Comment