Created
September 25, 2018 17:35
-
-
Save evie404/9bd5893d915b88023c6c78bf4c5b8b20 to your computer and use it in GitHub Desktop.
scala learning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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