I am counting the Consecutive Zeros and treating each one as separate block and pushing it to array blocks like this [3,1,1] , what i need to do is to push the position of first element in each block in another array like this [2,13,15]
var A = [1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0];
var N = A.length
function Avaiblocks(A,N,X){
var counter = 0;
var Blocks = [];
var POS =[];
for(var i = 0; i < A.length; i++) {
if(A[i] === 0){
counter++;
POS.push(i)
} else {
if (counter !== 0) {
Blocks.push(counter)
counter = 0;
}
}
}
if (counter !== 0){
Blocks.push(counter)
}
return POS;