File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Have the function powersOfTwo(num) take the num parameter being passed which
3
+ * will be an integer and return the string true if it's a power of two. If it's
4
+ * not return the string false. For example if the input is 16 then your program
5
+ * should return the string true but if the input is 22 then the output should
6
+ * be the string false.
7
+ *
8
+ * https://www.coderbyte.com/results/bhanson:Powers%20of%20Two:JavaScript
9
+ *
10
+ * @param {number } num
11
+ * @return {string } 'true' or 'false'
12
+ */
13
+ function powersOfTwo ( num ) {
14
+ return Number . isInteger ( Math . log ( num ) / Math . log ( 2 ) ) ? 'true' : 'false' ;
15
+ }
16
+
17
+ module . exports = powersOfTwo ;
Original file line number Diff line number Diff line change
1
+ const powersOfTwo = require ( './powers_of_two' ) ;
2
+
3
+ describe ( 'powersOfTwo()' , ( ) => {
4
+ test ( "returns 'true' for power of two" , ( ) => {
5
+ expect ( powersOfTwo ( 16 ) ) . toBe ( 'true' ) ;
6
+ expect ( powersOfTwo ( 256 ) ) . toBe ( 'true' ) ;
7
+ } ) ;
8
+
9
+ test ( "returns 'false' for not power of two" , ( ) => {
10
+ expect ( powersOfTwo ( 22 ) ) . toBe ( 'false' ) ;
11
+ expect ( powersOfTwo ( 257 ) ) . toBe ( 'false' ) ;
12
+ } ) ;
13
+ } ) ;
You can’t perform that action at this time.
0 commit comments