Skip to content

Commit

Permalink
Merge tag 'v0.2.5' into develop
Browse files Browse the repository at this point in the history
Bumped version
  • Loading branch information
adam-hanna committed Apr 16, 2018
2 parents 6a89988 + 9b26390 commit b587dfa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
30 changes: 21 additions & 9 deletions arrayOperations.go
Expand Up @@ -45,19 +45,23 @@ func Intersect(arrs ...interface{}) (reflect.Value, bool) {
// create a map to count all the instances of the slice elems
arrLength := len(arrs)
var kind reflect.Kind
var kindHasBeenSet bool

tempMap := make(map[interface{}]int)
for i, arg := range arrs {
for _, arg := range arrs {
tempArr, ok := Distinct(arg)
if !ok {
return reflect.Value{}, ok
}

// check to be sure the type hasn't changed
if i > 0 && tempArr.Index(0).Kind() != kind {
if kindHasBeenSet && tempArr.Len() > 0 && tempArr.Index(0).Kind() != kind {
return reflect.Value{}, false
}
kind = tempArr.Index(0).Kind()
if tempArr.Len() > 0 {
kindHasBeenSet = true
kind = tempArr.Index(0).Kind()
}

c := tempArr.Len()
for idx := 0; idx < c; idx++ {
Expand Down Expand Up @@ -100,19 +104,23 @@ func Union(arrs ...interface{}) (reflect.Value, bool) {
// create a temporary map to hold the contents of the arrays
tempMap := make(map[interface{}]uint8)
var kind reflect.Kind
var kindHasBeenSet bool

// write the contents of the arrays as keys to the map. The map values don't matter
for i, arg := range arrs {
for _, arg := range arrs {
tempArr, ok := Distinct(arg)
if !ok {
return reflect.Value{}, ok
}

// check to be sure the type hasn't changed
if i > 0 && tempArr.Index(0).Kind() != kind {
if kindHasBeenSet && tempArr.Len() > 0 && tempArr.Index(0).Kind() != kind {
return reflect.Value{}, false
}
kind = tempArr.Index(0).Kind()
if tempArr.Len() > 0 {
kindHasBeenSet = true
kind = tempArr.Index(0).Kind()
}

c := tempArr.Len()
for idx := 0; idx < c; idx++ {
Expand Down Expand Up @@ -143,18 +151,22 @@ func Difference(arrs ...interface{}) (reflect.Value, bool) {
// create a temporary map to hold the contents of the arrays
tempMap := make(map[interface{}]int)
var kind reflect.Kind
var kindHasBeenSet bool

for i, arg := range arrs {
for _, arg := range arrs {
tempArr, ok := Distinct(arg)
if !ok {
return reflect.Value{}, ok
}

// check to be sure the type hasn't changed
if i > 0 && tempArr.Index(0).Kind() != kind {
if kindHasBeenSet && tempArr.Len() > 0 && tempArr.Index(0).Kind() != kind {
return reflect.Value{}, false
}
kind = tempArr.Index(0).Kind()
if tempArr.Len() > 0 {
kindHasBeenSet = true
kind = tempArr.Index(0).Kind()
}

c := tempArr.Len()
for idx := 0; idx < c; idx++ {
Expand Down
4 changes: 4 additions & 0 deletions arrayOperations_unit_test.go
Expand Up @@ -22,6 +22,7 @@ func TestDistinct(t *testing.T) {
{stringArr2, true, []string{"b", "c", "e"}},
{intArr1, true, []uint64{1, 2, 4}},
{intArr2, true, []uint64{2, 3, 5}},
{[]int{}, true, []int{}},
}

for _, tt := range myTests {
Expand All @@ -45,6 +46,7 @@ func TestIntersect(t *testing.T) {
{stringArr1, stringArr2, true, []string{"b"}},
{intArr1, intArr2, true, []uint64{2}},
{stringArr1, intArr1, false, tempInterface},
{[]string{}, []string{"1"}, true, []string{}},
}

for _, tt := range myTests {
Expand All @@ -68,6 +70,7 @@ func TestUnion(t *testing.T) {
{stringArr1, stringArr2, true, []string{"a", "b", "c", "d", "e"}},
{intArr1, intArr2, true, []uint64{1, 2, 3, 4, 5}},
{stringArr1, intArr1, false, tempInterface},
{[]string{}, []string{"1"}, true, []string{"1"}},
}

for _, tt := range myTests {
Expand All @@ -91,6 +94,7 @@ func TestDifference(t *testing.T) {
{stringArr1, stringArr2, true, []string{"a", "c", "d", "e"}},
{intArr1, intArr2, true, []uint64{1, 3, 4, 5}},
{stringArr1, intArr1, false, tempInterface},
{[]string{}, []string{"1"}, true, []string{"1"}},
}

for _, tt := range myTests {
Expand Down

0 comments on commit b587dfa

Please sign in to comment.