diff options
| author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-11-07 07:50:23 -0500 |
|---|---|---|
| committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-11-09 19:47:16 -0500 |
| commit | 2cc0f9607872b8bd4fc6be2656a7b7a769b538b2 (patch) | |
| tree | 5e14b4ffcbf7c0d85f17b0ed468a08b4bafa11c1 /factors/slices.go | |
| parent | 7d2916a50187992f72e80ed667468e8c0b125d27 (diff) | |
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.
Diffstat (limited to 'factors/slices.go')
| -rw-r--r-- | factors/slices.go | 27 |
1 files changed, 27 insertions, 0 deletions
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 +} |
