Codility/1.1_binaryGap.js
// 10100: one binary gap of length 1
one binary gap of length 1
one binary gap of length 1
function solution(N) {
  const binary = N.toString(2);
  let gap = "", start = 1, BG = [];
  if(!binary.includes("0")) return 0; 
  for(let i = start; i < binary.length; i++) {
     if(binary[i] === "0") {
        gap += binary[i];
     } else {
        start = i;
        BG.push(gap.length);
        gap = "";
     } 
  }
  return BG.length ? Math.max(...BG) : 0;
}
function solution ( N ) { const binary = N . toString ( 2 ) ; let gap = "" , start = 1 , BG = [ ] ; if ( ! binary . includes ( "0" ) ) return 0 ; for ( let i = start ; i < binary . length ; i ++ ) { if ( binary [ i ] === "0" ) { gap += binary [ i ] ; } else { start = i ; BG . push ( gap . length ) ; gap = "" ; } } return BG . length ? Math . max ( ... BG ) : 0 ; }
10100: one binary gap of length 1
10100 : one binary gap of length 1
// edge case