Created
April 23, 2016 06:52
-
-
Save peterschmiz/4364f6f037feb2c51a9169a338492de7 to your computer and use it in GitHub Desktop.
This file contains 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) { | |
return parseInt(N, 10). | |
toString(2). | |
replace(/^0+|0+$/g, ''). | |
split('1'). | |
reduce(function (a, b) { | |
return a.length > b.length ? a : b; | |
}).length | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why you replacing the zero's (replace(/^0+|0+$/g, ''))? It can also works without.
Like that: return Number(N).toString(2).split('1').reduce(function (a, b) { return a.length > b.length ? a : b;}).length;
I just wont to understand the replace use. TY!