3 ms·
Like in a procedural language, you can precompute and keep the results. It's still more concise. I use Ocaml's tuples here to make a pair of the length/object b
by Raphael_Amiard 15y ago
Like in a procedural language, you can precompute and keep the results. It's still more concise. I use Ocaml's tuples here to make a pair of the length/object but you could use a struct/object/array/whatever:
let precomp = List.map lst (fun el -> ((length el), el)) in
let get_max (l1, el1) (l2, el2) = el1 if l1 > l2 else el2 in
List.reduce lst get_max