In this function I count the number of consecutive zeros that should be at least of length zerosMin. Is there any way I could return the first index of the start of the sequences? For example, for arr = [1,0,0,0,0,0,1,0,0,0,0]
it would be [1,7]
function SmallestBlockOfZeros(arr, zerosMin) {
let result = [];
let counter = 1;
for (let i = 0; i < arr.length; i++) {
if (arr[i] == 0) {
if (arr[i] === arr[i + 1]) {
counter++;
} else if (counter >= zerosMin) {
result.push(counter);
counter = 1;
} else {
counter = 1;
}
}
}
return result;
}
let arr = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0];
let zerosMin = 4;
console.log(SmallestBlockOfZeros(arr, zerosMin));
//Console output : [5,4]