Skip to content

Instantly share code, notes, and snippets.

@caelifer
Last active November 20, 2015 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caelifer/a5b2a7851720078f1caf to your computer and use it in GitHub Desktop.
Save caelifer/a5b2a7851720078f1caf to your computer and use it in GitHub Desktop.
// Implementation of merge task from http://raganwald.com/2015/11/03/a-coding-problem.html
package main
import (
"fmt"
"sort"
)
func main() {
tests := []struct {
a, b []int
}{
{
[]int{1, 7, 11, 17},
[]int{3, 5, 13},
},
{
[]int{2, 3, 5, 7, 11},
[]int{2, 4, 6, 8, 10, 12, 14},
},
}
for _, t := range tests {
fmt.Println(merge(t.a, t.b))
}
}
func merge(a, b []int) []int {
x := clone(a)
x = append(x, clone(b)...)
sort.Ints(x)
return x
}
func clone(x []int) []int {
return append(make([]int, 0, len(x)), x...)
}
@caelifer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment