The function ranges(list)
takes a sorted array of integers as input [-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]
and returns a string with ranges for the provided input "-6,-3-1,3-5,7-11,14,15,17-20"
.
A range must consist of three item, i.e. [1, 2]
is not considered a range.
A range is formatted as A-B
, e.g.: A = -7
, B = -1
, range is -7--1
.
A script by V.