github.com/jfrog/build-info-go@v1.9.26/utils/compareutils/compare.go (about) 1 package compareutils 2 3 import ( 4 "reflect" 5 "sort" 6 ) 7 8 // Compare two slices irrespective of elements order. 9 func IsEqualSlices(a, b []string) bool { 10 if len(a) != len(b) { 11 return false 12 } 13 14 a_copy := make([]string, len(a)) 15 b_copy := make([]string, len(b)) 16 17 copy(a_copy, a) 18 copy(b_copy, b) 19 20 sort.Strings(a_copy) 21 sort.Strings(b_copy) 22 23 return reflect.DeepEqual(a_copy, b_copy) 24 } 25 26 // Compare two dimensional slices irrespective of elements order. 27 func IsEqual2DSlices(a, b [][]string) bool { 28 return IsEqualSlices(To1DSlice(a), To1DSlice(b)) 29 } 30 31 // Transform two dimensional slice to one dimensional slice 32 func To1DSlice(a [][]string) (result []string) { 33 for _, i := range a { 34 temp := "" 35 for _, j := range i { 36 temp += j 37 } 38 result = append(result, temp) 39 } 40 return 41 }