-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpull.go
43 lines (37 loc) · 968 Bytes
/
pull.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
package slices
import (
"reflect"
"github.com/golodash/godash/generals"
"github.com/golodash/godash/internal"
)
// Removes all given values from slice.
//
// Complexity: O(n*m)
//
// n = length of 'slice'
//
// m = length of 'values'
func Pull(slice, values interface{}) interface{} {
if !internal.SliceCheck(slice) {
panic("passed 'slice' variable is not slice type")
}
if !internal.SliceCheck(values) {
panic("passed 'values' variable is not slice type")
}
sliceValue := reflect.ValueOf(slice)
outputValue := reflect.MakeSlice(sliceValue.Type(), 0, sliceValue.Len())
valuesValue := reflect.ValueOf(values)
for i := 0; i < sliceValue.Len(); i++ {
add := true
for j := 0; j < valuesValue.Len(); j++ {
if generals.Same(sliceValue.Index(i).Interface(), valuesValue.Index(j).Interface()) {
add = false
break
}
}
if add {
outputValue = reflect.Append(outputValue, sliceValue.Index(i))
}
}
return outputValue.Interface()
}