Check if a number is a power of another number | javascript program to check given number y is power of x { ; logarithm function to calculate value ; Note : this is var ; compare to the result1 or result2 both are equal ; Driver Code
function isPower ( x , y ) { var res1 = parseInt ( Math . log ( y ) ) / parseInt ( Math . log ( x ) ) ; var res2 = Math . log ( y ) / Math . log ( x ) ; return ( res1 == res2 ) ; } if ( isPower ( 27 , 729 ) ) document . write ( " " ) ; else document . write ( " " ) ;