Skip to content

Instantly share code, notes, and snippets.

@lricoy
Last active May 25, 2016 03:16
Show Gist options
  • Save lricoy/1e2cecf87e6c4986bd191145394fe95c to your computer and use it in GitHub Desktop.
Save lricoy/1e2cecf87e6c4986bd191145394fe95c to your computer and use it in GitHub Desktop.
Binary Gap solution
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