Skip to content

Instantly share code, notes, and snippets.

@tomaskikutis
Created April 17, 2016 16:39
Show Gist options
  • Save tomaskikutis/70c66a7c6752051b619d99568545b128 to your computer and use it in GitHub Desktop.
Save tomaskikutis/70c66a7c6752051b619d99568545b128 to your computer and use it in GitHub Desktop.
Codility
var trim = require("lodash/trim");
var max = require("lodash/max");
var dec2bin = function (dec){
return (dec >>> 0).toString(2);
};
var getLargestBinaryGap = function(n){
return max(
trim(dec2bin(n), "0")
.split("1")
.map(function(a){
return a.length;
})
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment