Advertisement
plantbae

isSorted FP Scala

Jan 21st, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.26 KB | None | 0 0
  1.   def isSorted[A](as: Array[A], ordered: (A,A) => Boolean): Boolean ={
  2.  
  3.     @annotation.tailrec
  4.  
  5.     def go(n: Int):Boolean=
  6.  
  7.       if(n == as.length -1) true
  8.  
  9.       else if (ordered(as(n), as(n+1))) false  
  10.  
  11.       else go(n + 1)
  12.  
  13.      
  14.  
  15.     go(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement