-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
61 lines (51 loc) · 1.2 KB
/
utils.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
58
59
60
61
package envi
import (
"os"
"strings"
)
func isExistPath(path string) bool {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
func removeAdjacentDuplicates(s string) string {
str := strings.Split(s, ``)
str = removeAdjacentDups(str)
return strings.Join(str, ``)
}
func removeAdjacentDuplicatesOnly(str, s string) string {
strA := strings.Split(str, ``)
strA = removeAdjacentDupsOnly(strA, s)
return strings.Join(strA, ``)
}
func removeAdjacentDups(strings []string) []string {
// Iterate over all characters in the slice except the last one
for i := 0; i < len(strings)-1; {
// Check whether the character next to it is a duplicate
if strings[i] == strings[i+1] {
// If it is, remove the CURRENT character from the slice
strings = append(strings[:i], strings[i+1:]...)
} else {
// If it's not, move to the next item in the slice
i++
}
}
return strings
}
func removeAdjacentDupsOnly(strings []string, s string) []string {
for i := 0; i < len(strings)-1; {
if s != strings[i] {
i++
continue
}
if strings[i] == strings[i+1] {
strings = append(strings[:i], strings[i+1:]...)
} else {
i++
}
}
return strings
}