Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created May 5, 2016 01:45
Show Gist options
  • Save JacobHsu/e3daf05cb582bdd152924a1e3b409a56 to your computer and use it in GitHub Desktop.
Save JacobHsu/e3daf05cb582bdd152924a1e3b409a56 to your computer and use it in GitHub Desktop.
/**
* @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