def isSorted[A](as: Array[A], ordering: (A, A) => Boolean): Boolean = {
@annotation.tailrec
def go(n: Int): Boolean =
if (n >= as.length - 1) true
else if (ordering(as(n), as(n + 1))) false
else go(n + 1)
go(0)
}
isSorted(Array(7, 5, 1, 3), (x: Int, y: Int) => x < y)
Login in to like
Login in to comment