Power of Three (Easy)
Good evening! Here's our prompt for today.
You may see this problem at Cisco, Autodesk, Vmware, Groupon, Flatiron Health, and Segment.
Given an integer num, write a method to determine if it is a power of 3.

The method will be called as follows:
JAVASCRIPT
1console.log(powerOfThree(9));
2// true
3
4console.log(powerOfThree(7));
5// falseConstraints
- The given would be a non zero positive integer in the range between
1and2147483647 - Expected space complexity :
O(logn) - Expected time complexity :
O(1)
xxxxxxxxxx34
var assert = require('assert');function powerOfThree(num) { // Fill in this method return num;}console.log(powerOfThree(9));console.log(powerOfThree(7));try { assert.equal(powerOfThree(9), true); console.log('PASSED: ' + 'powerOfThree(9) should be true');} catch (err) { console.log(err);}try { assert.equal(powerOfThree(7), false); console.log('PASSED: ' + 'powerOfThree(7) should be false');} catch (err) { console.log(err);}try {OUTPUT
Results will appear here.