SHARE
TWEET

finmd

a guest Apr 25th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. ;;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top