Extracts contiguous ranges from a pre-sorted array of numbers.
From this stackoverflow.com question: "How to convert sequence of numbers in an array to range of numbers"
This is CMS's answer, except negative numbers are in parenthesis.
NOTE: you may need to sort the array beforehand. One way is npm i --save sort-numbers
then
require('sort-numbers')(array);
var getRanges = ;;// returns ["2-5", "10", "18-20"]
To return an array of numeric ranges instead of strings describing ranges:
var getRanges = ;;// returns [[2,5], 10, [18,20]]