Junior
Merging numbers into ranges
livecode
Task condition
Given an array of integers. It is necessary to convert it into a string, combining consecutive numbers into ranges like "a-b", and leaving single numbers as they are. The result should be a string listing the ranges and numbers separated by commas.
// Input: [1, 4, 5, 2, 3, 9, 8, 11, 0]
// Output: "0-5,8-9,11"
// (Numbers 0, 1, 2, 3, 4, 5 form the range 0–5, 8 and 9 form the range 8–9, and 11 remains separate)