From 2cc0f9607872b8bd4fc6be2656a7b7a769b538b2 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Tue, 7 Nov 2023 07:50:23 -0500 Subject: Reduce golang requirement to go1.18 go1.21, the previous requirement, was released a few months ago, so not all systems have adopted it. go1.18 is old enough that most systems should support it, but it introduces generics, which my testing code is highly dependent on, so I can't easily go any earlier. --- factors/slices.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 factors/slices.go (limited to 'factors/slices.go') diff --git a/factors/slices.go b/factors/slices.go new file mode 100644 index 0000000..f2462cf --- /dev/null +++ b/factors/slices.go @@ -0,0 +1,27 @@ +package factors + +import "sort" + +func sortUints(s []uint) []uint { + sort.Slice(s, func(i, j int) bool { return s[i] < s[j] }) + return s +} + +func maxUints(s []uint) uint { + max := uint(0) + for _, n := range s { + if n > max { + max = n + } + } + return max +} + +func contains[S ~[]E, E comparable](s S, e E) bool { + for _, element := range s { + if e == element { + return true + } + } + return false +} -- cgit v1.2.3