Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. 'use strict';
  2.  
  3. function getLargestBinaryGap(input) {
  4. var binary = (input >>> 0).toString(2);
  5. var longestGap = 0;
  6. var matchArray = [];
  7. var regexp = /1{1}(0+)(?=1)/g;
  8.  
  9. while ((matchArray = regexp.exec(binary)) !== null) {
  10. let matchLength = matchArray[1].length;
  11.  
  12. if (matchLength > longestGap) {
  13. longestGap = matchLength;
  14. }
  15. }
  16.  
  17. return longestGap;
  18. }
  19.  
  20. console.log(getLargestBinaryGap(6));
  21. console.log(getLargestBinaryGap(1041));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement