-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.go
56 lines (46 loc) · 973 Bytes
/
array.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
package utils
import (
"strings"
)
func InArray[T comparable](needle T, haystack []T) bool {
for _, item := range haystack {
if item == needle {
return true
}
}
return false
}
func InListArray[T comparable](needles []T, haystack []T) bool {
for _, needle := range needles {
if InArray(needle, haystack) {
return true
}
}
return false
}
func Explode(separator string, stringStr string) []string {
if separator == "" {
return []string{stringStr}
}
return strings.Split(stringStr, separator)
}
func Implode(separator string, elements []string) string {
return strings.Join(elements, separator)
}
func Slice(arr []int, start, length int) []int {
if start < 0 {
start = len(arr) + start
}
end := start + length
if start < 0 || start > len(arr) || end < 0 {
return nil
}
if end > len(arr) {
end = len(arr)
}
return arr[start:end]
}
func Isset(array map[interface{}]interface{}, key any) bool {
_, ok := array[key]
return ok
}