Advertisement
Guest User

is_sorted

a guest
Mar 11th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.38 KB | None | 0 0
  1. (* Write a function is_sorted : string array -> bool which checks if the values of the input array are sorted in strictly increasing order, implying that its elements are unique (use String.compare). *)
  2.  
  3. let is_sorted a : bool =
  4.   let sorted = Array.fold_left (fun initial accumulator ->
  5.       String.compare accumulator initial) a.(0) a in
  6.   if sorted = 0
  7.   then true
  8.   else false
  9. ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement