-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
41 lines (38 loc) · 961 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package thesaurus
// Filter filters an array of strings based on a predicate function
func Filter(input []string, f func(string) bool) []string {
tmp := make([]string, 0)
for _, str := range input {
if f(str) {
tmp = append(tmp, str)
}
}
return tmp
}
// Ints returns a list of unique integers from a set of inputs.
func Ints(input []int) []int {
u := make([]int, 0, len(input))
// m is a map of what ints have been seen
m := make(map[int]bool)
// iterate over each value, then check to see if it's been seen: if not,
// record it, then add it to the array as a unique result
for _, val := range input {
if _, ok := m[val]; !ok {
m[val] = true
u = append(u, val)
}
}
// return the array of unique ints
return u
}
// Min returns the minimum value of an array of integers.
func Min(input []int) int {
// cap our minimum at the absolute max
min := 1<<31 - 1
for _, i := range input {
if i < min {
min = i
}
}
return 0
}