OCaml with list instead of array
let rec closest num list = match list with [] -> failwith "Empty list" |[n] -> n |h :: q -> let closest_q = closest num q in let val_h = abs (num - h) in let val_q = abs (num - closest_q) in if (val_h < val_q) then h else closest_q;;
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
OCaml with list instead of array