You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
384 B

package solutions
func IsSorted(f func(int, int) int, arr []int) bool {
ascendingOrdered := true
descendingOrdered := true
for i := 1; i < len(arr); i++ {
if !(f(arr[i-1], arr[i]) >= 0) {
ascendingOrdered = false
}
}
for i := 1; i < len(arr); i++ {
if !(f(arr[i-1], arr[i]) <= 0) {
descendingOrdered = false
}
}
return ascendingOrdered || descendingOrdered
}