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", "", ""]));
```
Here you go:

```js
function checkForSameConsecutives(haystack, needle, howMany) {
  let counter = 0;
  for (const el of haystack) {
    if (el === needle) {
      counter++;
      if (counter === howMany) {
        return true;
      }
    } else {
      counter = 0;
    }
  }
  return false;
}

```

Arguments to the function:

`haystack` - the array to search

`needle` - what are you searching for

`howMany` - how many hits do you need