Count groups of open cells around a cell on a grid
You could try using ramdajs. I solved it as follows but it could be way better

// indexes of the order to iterate in array square
const cord = [6, 7, 8, 5, 2, 1, 0, 3, 6];
const binaryRand = ()=&gt;  Number(Math.random() &lt; 0.5);

//const square = [1, 1, 1, 1, 0, 1, 0, 1, 0];
const square = R.times(binaryRand,9) 

const zeroToOne = (acc,curr,index)=&gt;{
  if(index === 0) return 0;
  return acc+= Number(!square[index-1] &amp;&amp; square[curr])
}

const countGroups = (square)=&gt;
  ((R.sum(square) - cord[4]) &lt; 8)?
     cord.reduce(zeroToOne,0) : 1;

countGroups(square);


here is the Ramdajs repel of the code.