Created
July 30, 2020 17:13
-
-
Save josefaidt/df90fc175ab63077167377488edcc8e8 to your computer and use it in GitHub Desktop.
find the longest binary gap from an integer input
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) { | |
// 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