Skip to content

Instantly share code, notes, and snippets.

@salamtamp
Last active September 22, 2018 17:12
Show Gist options
  • Save salamtamp/9258c2affae939edc0721bb81c33b5be to your computer and use it in GitHub Desktop.
Save salamtamp/9258c2affae939edc0721bb81c33b5be to your computer and use it in GitHub Desktop.
function bingap(n) {
const binary = (n >>> 0).toString(2);
const f1 = new RegExp(/1?0+1?/, 'g');
const f2 = new RegExp(/1(0+)1/);
return binary.match(f1)
.filter(r1 => r1.match(f2))
.reduce((acc, n) => acc > n.length - 2 ? acc : n.length - 2, 0)
}
console.log(bingap(42));
console.log(bingap(48));
console.log(bingap(49));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment