File tree Expand file tree Collapse file tree 3 files changed +59
-54
lines changed
src/hackerrank/interview_preparation_kit/miscellaneous Expand file tree Collapse file tree 3 files changed +59
-54
lines changed Original file line number Diff line number Diff line change 55const __BINARY_BASE__ = 2 ;
66const __NUMBER_SIZE_IN_BITS__ = 32 ;
77
8- export function flippingBits ( n ) {
8+ function flippingBits ( n ) {
99 let nBinaryStr = n . toString ( __BINARY_BASE__ ) ;
1010 nBinaryStr = nBinaryStr . padStart ( __NUMBER_SIZE_IN_BITS__ , '0' ) ;
1111
Original file line number Diff line number Diff line change 11import { describe , expect , it } from '@jest/globals' ;
22import { logger as console } from '../../../logger.js' ;
33
4- import { flippingBits } from './flipping-bits.js' ;
5-
6- const TEST_CASES = [
7- {
8- title : 'Sample Test Case 0' ,
9- tests : [
10- {
11- input : 2147483647 ,
12- expected : 2147483648
13- } ,
14- {
15- input : 1 ,
16- expected : 4294967294
17- } ,
18- {
19- input : 0 ,
20- expected : 4294967295
21- }
22- ]
23- } ,
24- {
25- title : 'Sample Test Case 1' ,
26- tests : [
27- {
28- input : 4 ,
29- expected : 4294967291
30- } ,
31- {
32- input : 123456 ,
33- expected : 4294843839
34- }
35- ]
36- } ,
37- {
38- title : 'Sample Test Case 2' ,
39- tests : [
40- {
41- input : 0 ,
42- expected : 4294967295
43- } ,
44- {
45- input : 802743475 ,
46- expected : 3492223820
47- } ,
48- {
49- input : 35601423 ,
50- expected : 4259365872
51- }
52- ]
53- }
54- ] ;
4+ import flippingBits from './flipping-bits.js' ;
5+ import TEST_CASES from './flipping-bits.testcases.json' ;
556
567describe ( 'flipping bits' , ( ) => {
578 it ( 'flipping bits test cases' , ( ) => {
589 expect . assertions ( 8 ) ;
5910
6011 TEST_CASES . forEach ( ( testSet ) => {
6112 testSet . tests . forEach ( ( test ) => {
62- const answer = flippingBits ( test . input ) ;
13+ const answer = flippingBits . flippingBits ( test . input ) ;
6314
6415 console . debug ( `flippingBits(${ test . input } ) solution found: ${ answer } ` ) ;
6516
@@ -74,7 +25,7 @@ describe('flipping bits', () => {
7425 const input = 9 ;
7526 const expected = 4294967286 ;
7627
77- const answer = flippingBits ( input ) ;
28+ const answer = flippingBits . flippingBits ( input ) ;
7829
7930 console . debug ( `flippingBits(${ input } ) solution found: ${ answer } ` ) ;
8031
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "title" : " Sample Test Case 0" ,
4+ "tests" :
5+ [
6+ {
7+ "input" : 2147483647 ,
8+ "expected" : 2147483648
9+ },
10+ {
11+ "input" : 1 ,
12+ "expected" : 4294967294
13+ },
14+ {
15+ "input" : 0 ,
16+ "expected" : 4294967295
17+ }
18+ ]
19+ },
20+ {
21+ "title" : " Sample Test Case 1" ,
22+ "tests" :
23+ [
24+
25+ {
26+ "input" : 4 ,
27+ "expected" : 4294967291
28+ },
29+ {
30+ "input" : 123456 ,
31+ "expected" : 4294843839
32+ }
33+ ]
34+ },
35+ {
36+ "title" : " Sample Test Case 2" ,
37+ "tests" :
38+ [
39+
40+ {
41+ "input" : 0 ,
42+ "expected" : 4294967295
43+ },
44+ {
45+ "input" : 802743475 ,
46+ "expected" : 3492223820
47+ },
48+ {
49+ "input" : 35601423 ,
50+ "expected" : 4259365872
51+ }
52+ ]
53+ }
54+ ]
You can’t perform that action at this time.
0 commit comments