Here I have a function that finds the range of values of array if they are in sequence if they break then it simple return the element
if i've an array const array2 = [[1, 2],[1, 3],[1, 4],[3, 8],[3, 11],[6, 1],[6, 2]]
then the output should be ['1,2-4', '3,8', '3,11', '6,1-2']
my function works fine for this type of array
but if i've an array that does not have the same format, for example, initially values are in sequence, then they aren't, and then they come back in sequence, the function fails.
const array = [[1, 2],[1, 3],[1, 4],[1, 5],[1, 7],[1, 9],[1, 12],[1, 13],[1, 14],[2, 5],[2, 6],[2, 7],[10, 2],[10, 8]];
it shows the output
['1,2-14', '1,7', '1,9', '1,12', '2,5-7', '7,6-7', '8,7', '8,9', '10,2', '10,8']
instead of this
['1,2-5', '1,7', '1,9', '1,12-14', '2,5-7', '7,6-7', '8,7', '8,9', '10,2', '10,8']]
here is the code link : https://codesandbox.io/s/hopeful-allen-3okc0p?file=/src/index.js:11-174