In JavaScript, how can I convert a sequence of numbers in an array to a range of numbers? In other words, I want to express consecutive occurring integers (no gaps) as hyphenated ranges.
[2,3,4,5,10,18,19,20]
would become [2-5,10,18-20]
[1,6,7,9,10,12]
would become [1,6-7,9-10,12]
[3,5,99]
would remain [3,5,99]
[5,6,7,8,9,10,11]
would become [5-11]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…