-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstringutils.go
More file actions
49 lines (40 loc) · 931 Bytes
/
stringutils.go
File metadata and controls
49 lines (40 loc) · 931 Bytes
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
package main
// Returns a string with the name of people who still need to answer, excluding people from the second slice
func formatUsers(groupIDs []string, answeredIDs []string) string {
var s string
for _, d := range groupIDs {
if !contains(answeredIDs, d) {
s += getNickname(d) + ", "
}
}
// Deletes the last comma
return s[:len(s)-2]
}
// Returns true if the slice contains the element d
func contains(slice []string, d string) bool {
for _, u := range slice {
if u == d {
return true
}
}
return false
}
// Returns the original slice minus the element str
func removeString(slice []string, str string) []string {
for i, v := range slice {
if v == str {
return append(slice[:i], slice[i+1:]...)
}
}
return slice
}
// Deletes every empty string in a slice
func cleanSlice(i *[]string) {
var tmp []string
for _, s := range *i {
if s != "" {
tmp = append(tmp, s)
}
}
*i = tmp
}