RosettaCodeData/Task/Comma-quibbling/OCaml/comma-quibbling-2.ocaml
2018-06-22 20:57:24 +00:00

15 lines
383 B
Text

open Core
let quibble = function
| [| |] -> "{}"
| [| a |] -> sprintf "{%s}" a
| array ->
let last, rest = Array.last array, Array.slice array 0 (-1) in
sprintf "{%s and %s}" (String.concat_array ~sep:", " rest) last
let test () =
[[||];
[|"ABC"|];
[|"ABC"; "DEF"|];
[|"ABC"; "DEF"; "G"; "H"|]]
|> List.iter ~f:(fun list -> print_endline (quibble list))