var countBinarySubstrings = function(s) { var result = []; var subMatch = function(str) { var sub1 = str.match(/^0+|1+/g)[0]; var sub2 = (Number(sub1[0]) ^ 1).toString().repeat(sub1.length); var reg = new RegExp(
^sub1{sub1}sub1{sub2}) console.log("test:", str, reg, reg.test(str)); if (reg.test(str)) { return
sub1{sub1}sub1{sub2}} return '' } for (var i=0,len=s.length;i<len-1;i++) { var sub = subMatch(s.slice(i)) console.log('sub:', sub); if (sub) { result.push(sub) } } return result.length };