Skip to content

Commit 546471f

Browse files
authored
Merge pull request #653 from sir-gon/refactor
Refactor
2 parents fe54b69 + 3091442 commit 546471f

File tree

95 files changed

+422
-360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+422
-360
lines changed

src/hackerrank/implementation/betweenTwoSets.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @link Problem definition [[docs/hackerrank/implementation/betweenTwoSets.md]]
33
*/
44

5-
export function isFactor(n, group) {
5+
function isFactor(n, group) {
66
let result = true;
77
let i = 0;
88

@@ -19,7 +19,7 @@ export function isFactor(n, group) {
1919
return result;
2020
}
2121

22-
export function factorOf(n, group) {
22+
function factorOf(n, group) {
2323
let result = true;
2424
let i = 0;
2525

@@ -36,7 +36,7 @@ export function factorOf(n, group) {
3636
return result;
3737
}
3838

39-
export function getTotalX(a, b) {
39+
function getTotalX(a, b) {
4040
let max = 0;
4141
for (const j of b) {
4242
if (j > max) max = j;
@@ -53,4 +53,5 @@ export function getTotalX(a, b) {
5353
return result.length;
5454
}
5555

56-
export default { getTotalX };
56+
export default { getTotalX, isFactor, factorOf };
57+
export { getTotalX, isFactor, factorOf };

src/hackerrank/implementation/birthday.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { logger as console } from '../../logger.js';
66

7-
export function birthday(s, d, m) {
7+
function birthday(s, d, m) {
88
let result = 0;
99
console.debug(`s: ${s}`);
1010

@@ -23,3 +23,4 @@ export function birthday(s, d, m) {
2323
}
2424

2525
export default { birthday };
26+
export { birthday };

src/hackerrank/implementation/bonAppetit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { logger as console } from '../../logger.js';
66

7-
export function bonAppetit(bill, k, b) {
7+
function bonAppetit(bill, k, b) {
88
const totalSum = bill.reduce(
99
(previousValue, currentValue) => previousValue + currentValue,
1010
0
@@ -25,3 +25,4 @@ export function bonAppetit(bill, k, b) {
2525
}
2626

2727
export default { bonAppetit };
28+
export { bonAppetit };

src/hackerrank/implementation/breakingRecords.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @link Problem definition [[docs/hackerrank/implementation/breakingRecords.md]]
33
*/
44

5-
export function breakingRecords(scores) {
5+
function breakingRecords(scores) {
66
if (scores.length === 0) {
77
throw new Error('Empty input');
88
}
@@ -29,3 +29,4 @@ export function breakingRecords(scores) {
2929
}
3030

3131
export default { breakingRecords };
32+
export { breakingRecords };

src/hackerrank/implementation/countApplesAndOranges.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @link Problem definition [[docs/hackerrank/implementation/countApplesAndOranges.md]]
33
*/
44

5-
export function countApplesAndOranges(s, t, a, b, apples, oranges) {
5+
function countApplesAndOranges(s, t, a, b, apples, oranges) {
66
let cApples = 0;
77
let cOranges = 0;
88

@@ -26,3 +26,4 @@ export function countApplesAndOranges(s, t, a, b, apples, oranges) {
2626
}
2727

2828
export default { countApplesAndOranges };
29+
export { countApplesAndOranges };

src/hackerrank/implementation/countingValleys.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { logger as console } from '../../logger.js';
66

7-
export function countingValleys(steps, path) {
7+
function countingValleys(steps, path) {
88
const stepList = path.split('');
99
let altitude = 0;
1010
let valleys = 0;
@@ -27,3 +27,4 @@ export function countingValleys(steps, path) {
2727
}
2828

2929
export default { countingValleys };
30+
export { countingValleys };

src/hackerrank/implementation/dayOfProgrammer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { daysInMonthNumber } from '../../constants/index.js';
77

88
const zeroPad = (num, places) => String(num).padStart(places, '0');
99

10-
export function dayOfProgrammer(year) {
10+
function dayOfProgrammer(year) {
1111
const dayToSearch = 256;
1212
let leap;
1313

@@ -51,3 +51,4 @@ export function dayOfProgrammer(year) {
5151
}
5252

5353
export default { dayOfProgrammer };
54+
export { dayOfProgrammer };

src/hackerrank/implementation/divisibleSumPairs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { logger as console } from '../../logger.js';
66

7-
export function divisibleSumPairs(n, k, ar) {
7+
function divisibleSumPairs(n, k, ar) {
88
let pairs = 0;
99
for (let i = 0; i < ar.length; i++) {
1010
for (let j = i + 1; j < ar.length; j++) {
@@ -19,3 +19,4 @@ export function divisibleSumPairs(n, k, ar) {
1919
}
2020

2121
export default { divisibleSumPairs };
22+
export { divisibleSumPairs };

src/hackerrank/implementation/gradingStudents.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @link Problem definition [[docs/hackerrank/implementation/gradingStudents.md]]
33
*/
44

5-
export function gradingStudents(grades) {
5+
function gradingStudents(grades) {
66
const minimum = 38;
77
const roundTo = 5;
88
const result = [];
@@ -23,3 +23,4 @@ export function gradingStudents(grades) {
2323
}
2424

2525
export default { gradingStudents };
26+
export { gradingStudents };

src/hackerrank/implementation/jumpingOnClouds.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { logger as console } from '../../logger.js';
66

7-
export function jumpingOnClouds(c) {
7+
function jumpingOnClouds(c) {
88
let result = 0;
99
let key = 0;
1010

@@ -26,3 +26,4 @@ export function jumpingOnClouds(c) {
2626
}
2727

2828
export default { jumpingOnClouds };
29+
export { jumpingOnClouds };

src/hackerrank/implementation/kangaroo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @link Problem definition [[docs/hackerrank/implementation/kangaroo.md]]
33
*/
44

5-
export function kangaroo(x1, v1, x2, v2) {
5+
function kangaroo(x1, v1, x2, v2) {
66
if (v1 === v2) {
77
if (x1 !== x2) return 'NO';
88
return 'YES';
@@ -18,3 +18,4 @@ export function kangaroo(x1, v1, x2, v2) {
1818
}
1919

2020
export default { kangaroo };
21+
export { kangaroo };

src/hackerrank/implementation/migratoryBirds.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import util from 'util';
66
import { logger as console } from '../../logger.js';
77

8-
export function migratoryBirds(arr) {
8+
function migratoryBirds(arr) {
99
if (arr.length === 0) {
1010
throw new Error('Empty input');
1111
}
@@ -35,3 +35,4 @@ export function migratoryBirds(arr) {
3535
}
3636

3737
export default { migratoryBirds };
38+
export { migratoryBirds };

src/hackerrank/implementation/minimumAbsoluteDifference.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { logger as console } from '../../logger.js';
66

7-
export function minimumAbsoluteDifference(arr) {
7+
function minimumAbsoluteDifference(arr) {
88
if (arr.length === 0) {
99
throw new Error('Empty input');
1010
}
@@ -31,3 +31,4 @@ export function minimumAbsoluteDifference(arr) {
3131
}
3232

3333
export default { minimumAbsoluteDifference };
34+
export { minimumAbsoluteDifference };

src/hackerrank/implementation/repeatedString.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { logger as console } from '../../logger.js';
66

7-
export function countAs(word) {
7+
function countAs(word) {
88
let result = 0;
99

1010
const chars = word.split('');
@@ -18,7 +18,7 @@ export function countAs(word) {
1818
return result;
1919
}
2020

21-
export function repeatedString(s, n) {
21+
function repeatedString(s, n) {
2222
let result = 0;
2323

2424
const blockSize = s.length;
@@ -32,4 +32,5 @@ export function repeatedString(s, n) {
3232
return result;
3333
}
3434

35-
export default { countAs };
35+
export default { repeatedString };
36+
export { repeatedString };

src/hackerrank/implementation/sockMerchant.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { logger as console } from '../../logger.js';
66

7-
export function sockMerchant(n, ar) {
7+
function sockMerchant(n, ar) {
88
let result = 0;
99

1010
const matches = {};
@@ -25,3 +25,4 @@ export function sockMerchant(n, ar) {
2525
}
2626

2727
export default { sockMerchant };
28+
export { sockMerchant };

src/hackerrank/interview_preparation_kit/arrays/2d_array.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ function hourglassSum(arr) {
5858
}
5959

6060
export default { hourglassSum };
61+
export { hourglassSum };

src/hackerrank/interview_preparation_kit/arrays/2d_array.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger.js';
33

4-
import twoDArray from './2d_array.js';
4+
import { hourglassSum } from './2d_array.js';
55
import TEST_CASES from './2d_array.testcases_test.json';
66

77
describe('arrays: 2d Array hourglassSum', () => {
88
it('hourglassSum Test Cases', () => {
99
expect.assertions(3);
1010

1111
TEST_CASES.forEach((test) => {
12-
const answer = twoDArray.hourglassSum(test.input);
12+
const answer = hourglassSum(test.input);
1313

1414
console.debug(
1515
`gethourGlass(${test.input.toString()}) solution found: ${answer}`

src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ function arrayManipulation(n, queries) {
2929
}
3030

3131
export default { arrayManipulation };
32+
export { arrayManipulation };

src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { logger as console } from '../../../logger.js';
33

44
import TEST_CASES from './cruch_testcases_test.json';
55

6-
import crush from './cruch_bruteforce.js';
6+
import { arrayManipulation } from './cruch_bruteforce.js';
77

88
describe('arrays: crush (bruteforce) small cases', () => {
99
it('arrayManipulation Test Cases', () => {
1010
expect.assertions(3);
1111

1212
TEST_CASES.forEach((test) => {
13-
const answer = crush.arrayManipulation(test.n, test.queries);
13+
const answer = arrayManipulation(test.n, test.queries);
1414

1515
console.debug(
1616
`arrayManipulation(${test.n}, ${test.queries}) solution found: ${answer}`

src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ function arrayManipulation(n, queries) {
2929
}
3030

3131
export default { arrayManipulation };
32+
export { arrayManipulation };

src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { logger as console } from '../../../logger.js';
33

44
import TEST_CASES from './cruch_testcases_test.json';
55

6-
import crush from './cruch_optimized.js';
6+
import { arrayManipulation } from './cruch_optimized.js';
77

88
describe('arrays: crush (optimized)', () => {
99
it('arrayManipulation Test Cases', () => {
1010
expect.assertions(3);
1111

1212
TEST_CASES.forEach((test) => {
13-
const answer = crush.arrayManipulation(test.n, test.queries);
13+
const answer = arrayManipulation(test.n, test.queries);
1414

1515
console.debug(
1616
`arrayManipulation(${test.n}, ${test.queries}) solution found: ${answer}`

src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md]]
33
*/
44

5-
export function rotLeftOne(aNumbers) {
5+
function rotLeftOne(aNumbers) {
66
const first = aNumbers.shift();
77
if (first !== undefined) {
88
aNumbers.push(first);
@@ -11,7 +11,7 @@ export function rotLeftOne(aNumbers) {
1111
return aNumbers;
1212
}
1313

14-
export function rotLeft(aNumbers, dRotations) {
14+
function rotLeft(aNumbers, dRotations) {
1515
let output = [...aNumbers];
1616

1717
for (let i = 0; i < dRotations; i++) {
@@ -22,3 +22,4 @@ export function rotLeft(aNumbers, dRotations) {
2222
}
2323

2424
export default { rotLeft, rotLeftOne };
25+
export { rotLeft };
Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,20 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger.js';
33

4-
import { rotLeft, rotLeftOne } from './ctci_array_left_rotation.js';
4+
import { rotLeft } from './ctci_array_left_rotation.js';
55

6-
const ROT_LEFT_ONE_TEST_CASES = [
7-
{ numbers: [1, 2, 3, 4, 5], expected: [2, 3, 4, 5, 1] },
8-
{ numbers: [2, 3, 4, 5, 1], expected: [3, 4, 5, 1, 2] },
9-
{ numbers: [3, 4, 5, 1, 2], expected: [4, 5, 1, 2, 3] },
10-
{ numbers: [4, 5, 1, 2, 3], expected: [5, 1, 2, 3, 4] },
11-
{ numbers: [5, 1, 2, 3, 4], expected: [1, 2, 3, 4, 5] }
12-
];
13-
14-
const ROT_LEFT_TEST_CASES = [
15-
{ numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] }
16-
];
6+
import ROT_LEFT_TEST_CASES from './ctci_array_left_rotation.testcases.json';
177

188
describe('ctci_array_left_rotation', () => {
19-
it('rotLeftOne Test Cases', () => {
20-
expect.assertions(5);
21-
22-
ROT_LEFT_ONE_TEST_CASES.forEach((value) => {
23-
const answer = rotLeftOne(value.numbers);
24-
25-
console.debug(`rotLeftOne(${value.numbers}) solution found: ${answer}`);
26-
27-
expect(answer).toStrictEqual(value.expected);
28-
});
29-
});
30-
319
it('rotLeft Test cases', () => {
32-
expect.assertions(1);
10+
expect.assertions(8);
3311

34-
ROT_LEFT_TEST_CASES.forEach((value) => {
35-
const answer = rotLeft(value.numbers, value.d_rotations);
12+
ROT_LEFT_TEST_CASES.forEach((test) => {
13+
const answer = rotLeft(test.input, test.d_rotations);
3614

37-
console.debug(`rotLeft(${value.numbers}) solution found: ${answer}`);
15+
console.debug(`rotLeft(${test.numbers}) solution found: ${answer}`);
3816

39-
expect(answer).toStrictEqual(value.expected);
17+
expect(answer).toStrictEqual(test.expected);
4018
});
4119
});
4220
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{"title": "Own 0", "input": [1, 2, 3, 4, 5], "d_rotations": 1, "expected": [2, 3, 4, 5, 1]},
3+
{"title": "Own 1", "input": [2, 3, 4, 5, 1], "d_rotations": 1, "expected": [3, 4, 5, 1, 2]},
4+
{"title": "Own 2", "input": [3, 4, 5, 1, 2], "d_rotations": 1, "expected": [4, 5, 1, 2, 3]},
5+
{"title": "Own 3", "input": [4, 5, 1, 2, 3], "d_rotations": 1, "expected": [5, 1, 2, 3, 4]},
6+
{"title": "Own 4", "input": [5, 1, 2, 3, 4], "d_rotations": 1, "expected": [1, 2, 3, 4, 5]},
7+
{"title": "Sample Test case 0", "input": [1, 2, 3, 4, 5], "d_rotations": 4, "expected": [5, 1, 2, 3, 4]},
8+
{"title": "Sample Test case 1", "input": [41, 73, 89, 7, 10, 1, 59, 58, 84, 77, 77, 97, 58, 1, 86, 58, 26, 10, 86, 51], "d_rotations": 10, "expected": [77, 97, 58, 1, 86, 58, 26, 10, 86, 51, 41, 73, 89, 7, 10, 1, 59, 58, 84, 77]},
9+
{"title": "Sample Test case 2", "input": [33, 47, 70, 37, 8, 53, 13, 93, 71, 72, 51, 100, 60, 87, 97], "d_rotations": 13, "expected": [87, 97, 33, 47, 70, 37, 8, 53, 13, 93, 71, 72, 51, 100, 60]}
10+
]

0 commit comments

Comments
 (0)