Question: Hello i have to check Arrays(all have equal lengths) which have same elements(null in mycase) in atleast 4 consecutive positions. and return true if it has so.

Example,

```
Arr1 = ["a","","b","c","","","","","d"]; // if array is like this it should return - True
Arr1 = ["","","","","","a","b","c","d"]; // if it is like this it should return - True
Arr1 = ["p","q","","r","","","s","",""]; // if it is like this it should return - False

```

Any idea?? Please Help advise or suggest somecode in the below function so to acheive this requirement in javascript

```
function checkForSameConsecutives(arr) {

 //somecode here 

 // if condition to return true/false;
};
checkForSameConsecutives(Arr1);

```

Answer: 
You could take a closure over a counter `c` and check the value and reset if the value is truthy or add one. Then return the result of the check with the wanted length.

```js
const check = array => (c => array.some(v => (c = v ? 0 : c + 1) === 4))(0);

console.log(check(["a", "", "b", "c", "", "", "", "", "d"]));
console.log(check(["", "", "", "", "", "a", "b", "c", "d"]));
console.log(check(["p", "q", "", "r", "", "", "s", "", ""]));
```
Try this

```js
Arr1 = ["a","","b","c","","","","","d"]; // if array is like this it should return - True
Arr2 = ["","","","","","a","b","c","d"]; // if it is like this it should return - True
Arr3 = ["p","q","","r","","","s","",""]; // if it is like this 
function checkForSameConsecutives(arr) {
  for(let i=0; i < arr.length - 3; i+=1){
    const ArrayToCheck = arr.slice(i, i+4)
    const ArrayToCheckSet = new Set(ArrayToCheck)
    if(ArrayToCheckSet.size === 1){
      return true
    }
  }
  return false
};

console.log(checkForSameConsecutives(Arr1))
console.log(checkForSameConsecutives(Arr2))
console.log(checkForSameConsecutives(Arr3))
```

This is not most optimised. But might give you some direction. Here code is iterating on every index and checking if next three elements are same.