Skip to content

Instantly share code, notes, and snippets.

@Akii
Created August 3, 2015 18:40
Show Gist options
  • Save Akii/495812e5ff4d0826b73c to your computer and use it in GitHub Desktop.
Save Akii/495812e5ff4d0826b73c to your computer and use it in GitHub Desktop.
def isSorted[A](as: Array[A], ordered: (A,A) => Boolean): Boolean = {
if (as.length <= 1) true
else {
@annotation.tailrec
def checkSort(n: Int): Boolean = {
if (n >= as.length) true
else if (!ordered(as(n - 1), as(n))) false
else checkSort(n+1)
}
checkSort(1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment