summaryrefslogtreecommitdiff
path: root/lib/js_lib/array.ml
blob: e55f1e98ee8aa6c4cb85d4b0ae0965312e2a51ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
open Js_of_ocaml

(** Compare two arrays *)
let compare
  : f:('a -> 'a -> bool Js.t) -> 'a Js.js_array Js.t -> 'a Js.js_array Js.t -> bool Js.t
  = fun ~f arr1 arr2 ->
    if arr1##.length <> arr2##.length then
      Js._false
    else
      arr1##every
        (Js.wrap_callback @@ fun elem i _ ->
         Js.Optdef.case (Js.array_get arr2 i)
           (fun () -> Js._false)
           (fun elem2 -> f elem elem2))