forked from expr-lang/expr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_misc.go
More file actions
50 lines (42 loc) · 872 Bytes
/
func_misc.go
File metadata and controls
50 lines (42 loc) · 872 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
50
package expr
import (
"reflect"
)
func contains(needle interface{}, array interface{}) interface{} {
arr, ok := asArray(array)
if !ok {
return false
}
if an, ok := asArray(needle); ok {
cnt := len(an)
out := make([]interface{}, cnt)
for i := 0; i < cnt; i++ {
out[i] = containsImpl(an[i], arr)
}
return out
}
return containsImpl(needle, arr)
}
func notcontains(needle interface{}, array interface{}) interface{} {
arr, ok := asArray(array)
if !ok {
return true
}
if an, ok := asArray(needle); ok {
cnt := len(an)
out := make([]interface{}, cnt)
for i := 0; i < cnt; i++ {
out[i] = !containsImpl(an[i], arr)
}
return out
}
return !containsImpl(needle, arr)
}
func containsImpl(needle interface{}, arr []interface{}) bool {
for _, v := range arr {
if reflect.DeepEqual(needle, v) {
return true
}
}
return false
}