aboutsummaryrefslogtreecommitdiff
path: root/lib/ints/ints_example_test.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2019-09-24 22:40:55 +0700
committerShulhan <m.shulhan@gmail.com>2019-09-24 22:40:55 +0700
commit832adfee60a040fe23150d0e4a40c0066b70a73f (patch)
treeb27eae6756974b75663a2a112157d462bbdd4a46 /lib/ints/ints_example_test.go
parent7eacd3ade3ecc83ee59ca8ce14cb60c2082096a3 (diff)
downloadpakakeh.go-832adfee60a040fe23150d0e4a40c0066b70a73f.tar.xz
ints: add function to merge two slices of integers by distance
MergeByDistance merge two slice of integers by their distance between each others. For example, if slice a contains "{1, 5, 9}" and b contains "{4, 11, 15}" and the distance is 3, the output of merged is "{1, 5, 9, 15}". The 4 and 11 are not included because 4 is in range between 1 and (1+3), and 11 is in range between 9 and 9+3.
Diffstat (limited to 'lib/ints/ints_example_test.go')
-rw-r--r--lib/ints/ints_example_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/ints/ints_example_test.go b/lib/ints/ints_example_test.go
index 98fd908b..f29fe748 100644
--- a/lib/ints/ints_example_test.go
+++ b/lib/ints/ints_example_test.go
@@ -15,3 +15,16 @@ func ExampleMax() {
// Output:
// 9 4 true
}
+
+func ExampleMergeByDistance() {
+ a := []int{1, 5, 9}
+ b := []int{4, 11, 15}
+
+ ab := MergeByDistance(a, b, 3)
+ ba := MergeByDistance(b, a, 3)
+ fmt.Println(ab)
+ fmt.Println(ba)
+ // Output:
+ // [1 5 9 15]
+ // [1 5 9 15]
+}