-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutilities.go
46 lines (39 loc) · 1.02 KB
/
utilities.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
/*
utilities.go
Description:
All the files which are useful for manipulating objects in the OzayGroupExploration
reppository but which are not attached to a specific type/class.
*/
package OzayGroupExploration
/*
FindStringInSlice
Description:
Finds if the string stringIn is in the slice stringSliceIn.
*/
func FindStringInSlice(stringIn string, stringSliceIn []string) (int, bool) {
// Initialize search parameters
stringIndex := -1
// Search
for tempIndex, tempString := range stringSliceIn {
if tempString == stringIn {
stringIndex = tempIndex
}
}
// Return result
return stringIndex, stringIndex >= 0
}
/*
AppendStringToSliceIfUnique
Description:
Appends the string to the slice stringSliceIn only if stringIn is not already in there.
*/
func AppendStringToSliceIfUnique(stringIn string, stringSliceIn []string) []string {
// Constants
// Algorithm
_, tf := FindStringInSlice(stringIn, stringSliceIn)
if tf {
return stringSliceIn
}
// If not, then append string
return append(stringSliceIn, stringIn)
}