Created
May 5, 2016 01:45
-
-
Save JacobHsu/e3daf05cb582bdd152924a1e3b409a56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} n | |
* @return {boolean} | |
*/ | |
var isPowerOfThree = function(n) { | |
return n.toString(3).replace(/0/g, '') === '1'; | |
}; | |
/* | |
Given an integer, write a function to determine if it is a power of three. | |
--- | |
var n1 = 9; | |
console.log( n1.toString(3) ); // "100" | |
var n2 = 27; | |
console.log( n2.toString(3) ); // "1000" | |
console.log( "100".replace(/0/g, '') ); //1 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment