Function to return the highest power of k less than or equal to n
function prevPowerofK ( n , k ) { var p = parseInt ( Math . log ( n ) / Math . log ( k ) ) ; return parseInt ( Math . pow ( k , p ) ) ; }