This function converts a number into its digit vector and uses above function to compute the answer
function countInRange ( x ) { num = [ ] ; while ( x != 0 ) { num . push ( x % 10 ) ; x = Math . floor ( x / 10 ) ; } num . reverse ( ) ;