I am struggling to find a way to identify if a sorted Array consists of 5 numbers in consecutive order. The catch here is that the Array can have duplicate and double-digit numbers mixed within it.
I attempted to implement this logic but unfortunately, my approach seems to be falling short.
var array = [1,3,5,7,7,8,9,10,11]
var current = null;
var count = 0;
for (var i = 0; i < array.length; i++) {
if (array[i] != current) {
if (count > 4) {
return true;
}
current = array[i];
count = 1;
} else {
count++;
}
}
if (count > 4) {
return true;
}