Advertisement
Guest User

Untitled

a guest
May 26th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. /*
  2. Given an integer, write a function to determine if it is a power of three.
  3.  
  4. Follow up:
  5. Could you do it without using any loop / recursion?
  6. */
  7.  
  8. /**
  9. * @param {number} n
  10. * @return {boolean}
  11. */
  12. var isPowerOfThree = function(n) {
  13. return n > 0 && Math.pow(3, Math.round(Math.log(n)/Math.log(3))) == n
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement