Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // you can write to stdout for debugging purposes, e.g.
- // console.log('this is a debug message');
- function solution(N) {
- var max = 0,
- count = false,
- zeros = 0;
- while (N >= 1) {
- if (N % 2 === 0) {
- if (count) zeros += 1;
- }
- else {
- if (zeros > max) {
- max = zeros;
- }
- zeros = 0;
- count = true;
- }
- N = parseInt(N / 2);
- }
- return max;
- }
- // test result
- var results = {
- total: 0,
- bad: 0
- };
- // function to test function
- function test(functionToTest, args, expected) {
- results.total++;
- var result = functionToTest.apply(this, args);
- if (result !== expected) {
- results.bad++;
- console.log("Expected " + expected + ", but was " + result);
- }
- }
- // show results function
- function showTestResults() {
- console.log("Of %d tests, %d failed, %d passed.", results.total, results.bad, (results.total - results.bad));
- }
- // test start
- test(solution, [9], 2);
- test(solution, [529], 4);
- test(solution, [20], 1);
- test(solution, [15], 0);
- test(solution, [1041], 5);
- test(solution, [0], 0);
- test(solution, [1], 0);
- test(solution, [66561], 9);
- test(solution, [74901729], 4);
- test(solution, [100000], 4);
- test(solution, [51712], 2);
- // show results
- //showTestResults();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement