Function to check if a number can be expressed as a ^ b .
function isPower ( a ) { if ( a == 1 ) return true ; for ( let i = 2 ; i * i <= a ; i ++ ) { let val = Math . log ( a ) / Math . log ( i ) ; if ( ( val - parseInt ( val ) < 0.00000001 ) ) return true ; } return false ; }