Beispiel #1
0
// Same as CompareSlice, but only compare the string slice.
func CompareStringSlice(v1, v2 []string) int {
	len1, len2 := len(v1), len(v2)
	_len := extremum.MinInt(len1, len2)
	for i := 0; i < _len; i++ {
		diff := strings.Compare(v1[i], v2[i])
		if diff != 0 {
			return diff
		}
	}

	if len1 == len2 {
		return 0
	} else if len1 < len2 {
		return -1
	} else {
		return 1
	}
}
Beispiel #2
0
// Same as CompareSlice, but only compare the int slice.
func CompareIntSlice(v1, v2 []int) int {
	len1, len2 := len(v1), len(v2)
	_len := extremum.MinInt(len1, len2)
	for i := 0; i < _len; i++ {
		if v1[i] < v2[i] {
			return -1
		} else if v1[i] > v2[i] {
			return 1
		}
	}

	if len1 == len2 {
		return 0
	} else if len1 < len2 {
		return -1
	} else {
		return 1
	}
}