Skip to content

Instantly share code, notes, and snippets.

@josefaidt
Created July 30, 2020 17:13
Show Gist options
  • Save josefaidt/df90fc175ab63077167377488edcc8e8 to your computer and use it in GitHub Desktop.
Save josefaidt/df90fc175ab63077167377488edcc8e8 to your computer and use it in GitHub Desktop.
find the longest binary gap from an integer input
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
return parseInt(N >>> 0).toString(2).split('1').reduce((acc, value, index, self) => value.length > acc ? (typeof self[index + 1] === 'string' ? value.length : acc) : acc, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment