Search⌘ K

Solution Review: Number Sequence

Explore how to apply ReasonML's conditional expressions to solve number sequence challenges. Understand the use of switch expressions for multiple cases and compare with if-else and ternary expressions to handle value ranges effectively.

Solution 1: switch Expression

Reason
let n = 5;
let next = switch (n) {
/* Take care of all cases */
| 0 => 1
| 1 => 2
| 2 => 3
| 3 => 4
| 4 => 5
| 5 => 6
| 6 => 7
| 7 => 8
| 8 => 9
| 9 => 10
| _ => -1 /* In case n is out of range */
};
Js.log(next);

Explanation

The most effective approach is ...