Given a sorted array of ints for example
a = [0,1,2,5,6,9];
I would like to identify the ranges like
[
[0,1,2],
[5,6],
[9]
]
So far I have tried a double/triple loop but it nests to really nasty code. Maybe this problem can be solved using recursion or other smart tricks?
Additional example:
input
b = [0,1,5,6,7,9];
output
[
[0,1],
[5,6,7],
[9]
]