I have the following array :
var selectedRange = [
null,
null,
null,
null,
null,
null,
null,
null,
9, //sequences
10,//sequences
null,
12,
13,
14,
null,
null,
null,
null,
null,
20,
null,
null,
null,
null,
25,
null,
null,
null,
29,
30,
31,
32,
null,
null,
null,
null,
37,
38,
null,
40,
41,
42,
null,
44,
null,
null,
47,
null,
49,
50,
null,
null,
null,
null,
null,
null
]
I need to extract sequences of number and only numbers - so the result would be like:
["9,10", "12,13,14", "20", "25", "29,30,31,32", "44", "47", "49,50"]
The problem is that I can't come up with a solution to extract a sequence as it is, I guess I need a recursive function that repeats the part of checking if the last number and the current are following - like here ...(!!prm && (prm - (index-1) ==1 )
let tempArr = [];
$.each(selectedRange, function (index, prm) {
if (!!prm && (prm - (index - 1) == 1) {
tempArr.push(prm); // need to loop this section with recursion
}
});