I need to implement a function that accepts two parameters - the number of 0 and the number of 1 and determine how many ways to place these 0 and 1 so that there are no two zeros in a row.
For example, I need to find all methods of placing two 0 and two 1.
There are six possible ways to place them: 0011, 0101, 0110, 1001, 1010, 1100.
In three cases there are two zeros in a row: 0011, 1001 and 1100.
I subtract them from the total number and get three possible ways: 0101, 0110 and 1010. So the answer is 3.
First, I'm trying to write script to recognize which cases I need
let arr = ["1100","1010","1001","0011","0101","0110"]
let result = [];
for (let i = 0; i < arr.length; i++){
let expVal = arr[i];
for (let p = 0; p < expVal.length; p++){
if (expVal[p] === expVal[p++] || expVal[p] === "0"){
result.push(expVal)
}
}
}
console.log(result);
It's does not work. I don't know how to fix it. And I don't understand what I need to do later