Reduces consecutive elements of an array of integers into ranges.