Advertisement
Guest User

finmd

a guest
Apr 25th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.48 KB | None | 0 0
  1. (* 1. Write a function find : string array -> string -> int option such that find a w = Some idx if a.(idx) = w and find a w = None if there is no such index. *)
  2.  
  3. let find (str_arr : string array) (str : string) : int option =
  4.   let start = 0 in
  5.   let rec found (index: int) (arr: string array) : int option =
  6.     if index < Array.length(arr)
  7.     then
  8.       if str = arr.(index)
  9.       then Some index
  10.       else found (index + 1) arr
  11.     else None
  12.   in
  13.   found start str_arr
  14. ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement