File tree Expand file tree Collapse file tree 3 files changed +680
-82
lines changed Expand file tree Collapse file tree 3 files changed +680
-82
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ author: @Aayushi-Mittal
3+
4+ This script will check whether the given
5+ number is a power of two or not.
6+
7+ */
8+
9+ export const IsPowerOfTwo = ( n ) => {
10+ if ( ( n & ( n - 1 ) ) == 0 && n != 0 )
11+ return true ;
12+ else
13+ return false ;
14+ }
15+
16+ // console.log(IsPowerOfTwo(0));
17+
Original file line number Diff line number Diff line change 1+ import { IsPowerOfTwo } from '../IsPowerOfTwo'
2+
3+ test ( 'Check if 0 is a power of 2 or not:' , ( ) => {
4+ const res = IsPowerOfTwo ( 1 , 0 )
5+ expect ( res ) . toBe ( false )
6+ } )
7+
8+ test ( 'Check if 4 is a power of 2 or not:' , ( ) => {
9+ const res = IsPowerOfTwo ( 4 )
10+ expect ( res ) . toBe ( true )
11+ } )
12+
13+ test ( 'Check if 1024 is a power of 2 or not:' , ( ) => {
14+ const res = IsPowerOfTwo ( 1024 )
15+ expect ( res ) . toBe ( true )
16+ } )
17+
18+ test ( 'Check if 1025 is a power of 2 or not:' , ( ) => {
19+ const res = IsPowerOfTwo ( 1025 )
20+ expect ( res ) . toBe ( false )
21+ } )
You can’t perform that action at this time.
0 commit comments