Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, December 10, 2016

Codefights rangeBitCount


//sample solution

function onesCount(x)
{
    var count=0;
    while(x){
    count++;
        x = x & (x - 1);
    }  
    return count;
}

function rangeBitCount(a, b) {
    var sumOfOnesCount = 0;
    for(i=a; i<=b; i++){
        sumOfOnesCount = sumOfOnesCount + onesCount(i);
    }
    return sumOfOnesCount;
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts