In javascript how to convert sequence of numbers in an array to range of numbers?
eg. [2,3,4,5,10,18,19,20]
to [2-5,10,18-20]
In javascript how to convert sequence of numbers in an array to range of numbers?
eg. [2,3,4,5,10,18,19,20]
to [2-5,10,18-20]
I needed a PHP version that also supports downward ranges (e.g.
[10,9,8]
gets converted to[10-8]
). So I have modified DisgruntledGoat's version who ported CMS's solution. It also handles Strings in the input properly.Example:
Very nice question: here's my attempt:
Demo on JSFiddler
In C#