Last active
May 25, 2016 03:16
-
-
Save lricoy/1e2cecf87e6c4986bd191145394fe95c to your computer and use it in GitHub Desktop.
Binary Gap solution
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 solution(N) { | |
const binN = (N >>> 0).toString(2); | |
const untrailed = binN.slice(0, binN.lastIndexOf(1) + 1); | |
return untrailed.split(1) | |
.filter(x => x.indexOf('0') > -1) | |
.reduce((val, acc) => val.length > acc.length ? val : acc, '') | |
.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment