Nth term of Ruler Function Series | Function to count the number of set bits in the number N ; Store the number of setbits ; Update the value of n ; Update the count ; Return the total count ; Function to find the Nth term of the Ruler Function Series ; Store the result ; Print the result ; Driver code
function setBits ( n ) { var count = 0 ; while ( n > 0 ) { n = n & ( n - 1 ) ; count ++ ; } return count ; } function findNthTerm ( N ) { var x = setBits ( N ^ ( N - 1 ) ) ; document . write ( x ) ; } var N = 8 ; findNthTerm ( N ) ;