Jane Street OCaml Challenge: Range and Append
The append operator (@)
concatenates two lists.
let () =
assert ([%compare.equal: int list] ([5; 1] @ [8; 4]) [5; 1; 8; 4]);
assert ([%compare.equal: int list] (List.append [5; 1] [8; 4]) [5; 1; 8; 4])
Your Task: Implement range
Construct a list of all integers from from
to to_
, including from
but excluding to_
, in increasing order.
let range from to_ = failwith "For you to implement"
Example: range 1 4
should return [1; 2; 3]
Tests for range
let%test "Testing range..." = [%compare.equal: int list] (range 1 4) [1; 2; 3]
let%test "Testing range..." =
[%compare.equal: int list] (range (-5) 3) [-5; -4; -3; -2; -1; 0; 1; 2]