Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 10, 2015 12:38
Show Gist options
  • Save shigemk2/6e3bfd1a433869c4d5f0 to your computer and use it in GitHub Desktop.
Save shigemk2/6e3bfd1a433869c4d5f0 to your computer and use it in GitHub Desktop.
def isSorted[A](as: Array[A], lt: (A,A) => Boolean): Boolean = {
// @annotation.tailrec
if (as.length <= 1) true
else if (lt(as(0), as(1))) isSorted(as.tail, lt)
else false
}
println(isSorted[Int](Array(1,2,3), _<_))
println(isSorted[Int](Array(3,1,2), _<_))
println(isSorted[Int](Array(), _<_))
println(isSorted[Int](Array(1), _<_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment