Last active
September 22, 2018 17:12
-
-
Save salamtamp/9258c2affae939edc0721bb81c33b5be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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