Skip to content

Instantly share code, notes, and snippets.

@evie404
Created September 25, 2018 17:35
Show Gist options
  • Save evie404/9bd5893d915b88023c6c78bf4c5b8b20 to your computer and use it in GitHub Desktop.
Save evie404/9bd5893d915b88023c6c78bf4c5b8b20 to your computer and use it in GitHub Desktop.
scala learning
def isSorted[A](as: Array[A], ordered: (A,A) => Boolean): Boolean = {
def go[A](as: Array[A], ordered: (A, A) => Boolean, acc: Int): Boolean = {
if (acc == 2) {
ordered(as(0), as(1))
} else {
if (ordered(as(acc - 2), as(acc - 1))) {
go(as, ordered, acc - 1)
} else {
false
}
}
}
go(as, ordered, as.length)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment