-
Notifications
You must be signed in to change notification settings - Fork 102
/
util.go
57 lines (46 loc) · 926 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package util
import (
"sort"
"strconv"
"strings"
)
func SliceAtoi(stringSlice []string) ([]int, error) {
var intSlice = []int{}
for _, stringValue := range stringSlice {
intValue, err := strconv.Atoi(stringValue)
if err != nil {
return intSlice, err
}
intSlice = append(intSlice, intValue)
}
return intSlice, nil
}
func SliceItoa(intSlice []int) []string {
var stringSlice = []string{}
for _, intValue := range intSlice {
stringValue := strconv.Itoa(intValue)
stringSlice = append(stringSlice, stringValue)
}
return stringSlice
}
func ContainsInt(s []int, e int) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
func ContainsString(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
func SplitAndSort(s string, sep string) []string {
slice := strings.Split(s, sep)
sort.Strings(slice)
return slice
}