javascript - I want the elements which are in sequence (1,2,3) (6,7) (10,11) (15,16,17). separately -
am having following array:arrtooth
var arrtooth = tooth.split('|');
it gets value
arrtooth=[1,2,3,6,7,10,11,15,16,17];
i want elements in sequence (1,2,3) (6,7) (10,11) (15,16,17)
. separately.my code in jquery.i want actual logic.
if output 3 2 2 3 in array fine or if have thing (output) can elaborate sequence ok.
var arrtooth = [1, 2, 3, 6, 7, 10, 11, 15, 16, 17]; var last = arrtooth[0]; var result = []; count = 1; (var = 1; < arrtooth.length; i++) { if (arrtooth[i] == (last + 1)) { count++; } else { result.push(count); count = 1; } last = arrtooth[i]; } result.push(count);
Comments
Post a Comment