Skip to content

Commit b2e0d7a

Browse files
authored
Revert "Refactor"
1 parent e01cf89 commit b2e0d7a

11 files changed

+84
-47
lines changed

src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.js

Lines changed: 2 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-
function rotLeftOne(aNumbers) {
5+
export function rotLeftOne(aNumbers) {
66
const first = aNumbers.shift();
77
if (first !== undefined) {
88
aNumbers.push(first);
@@ -11,7 +11,7 @@ function rotLeftOne(aNumbers) {
1111
return aNumbers;
1212
}
1313

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

1717
for (let i = 0; i < dRotations; i++) {
Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger.js';
33

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

6-
import ROT_LEFT_TEST_CASES from './ctci_array_left_rotation.testcases.json';
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+
];
717

818
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+
931
it('rotLeft Test cases', () => {
10-
expect.assertions(8);
32+
expect.assertions(1);
1133

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

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

17-
expect(answer).toStrictEqual(test.expected);
39+
expect(answer).toStrictEqual(value.expected);
1840
});
1941
});
2042
});

src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.js

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

5-
function minimumSwaps(arr) {
5+
export function minimumSwaps(arr) {
66
const indexedGroup = arr.map((x) => x - 1);
77
let swaps = 0;
88
let index = 0;

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

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

4-
import ms2 from './minimum_swaps_2.js';
4+
import { minimumSwaps } from './minimum_swaps_2.js';
55

6-
import TEST_CASES from './minimum_swaps_2.testcases.json';
6+
const TEST_CASES = [
7+
{ title: 'Sample input 0', input: [4, 3, 1, 2], expected: 3 },
8+
{ title: 'Sample input 1', input: [2, 3, 4, 1, 5], expected: 3 },
9+
{ title: 'Sample input 2', input: [1, 3, 5, 2, 4, 6, 7], expected: 3 }
10+
];
711

812
describe('minimum swaps 2', () => {
913
it('minimumSwaps', () => {
1014
expect.assertions(3);
1115

1216
TEST_CASES.forEach((test) => {
13-
const answer = ms2.minimumSwaps(test.input);
17+
const answer = minimumSwaps(test.input);
1418

1519
console.debug(`minimumSwaps(${test.input}) solution found: ${answer}`);
1620

src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.testcases.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1.big.testcases.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,32 @@ import { logger as console } from '../../../logger.js';
33

44
import { countTriplets } from './count_triplets_1_bruteforce.js';
55

6-
import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';
6+
const SMALL_TEST_CASES = [
7+
{
8+
title: 'Sample Test Case 0',
9+
input: [1, 2, 2, 4],
10+
r: 2,
11+
expected: 2
12+
},
13+
{
14+
title: 'Sample Test Case 1',
15+
input: [1, 3, 9, 9, 27, 81],
16+
r: 3,
17+
expected: 6
18+
},
19+
{
20+
title: 'Sample Test Case 1 (unsorted)',
21+
input: [9, 3, 1, 81, 9, 27],
22+
r: 3,
23+
expected: 1
24+
},
25+
{
26+
title: 'Sample Test Case 12',
27+
input: [1, 5, 5, 25, 125],
28+
r: 5,
29+
expected: 4
30+
}
31+
];
732

833
describe('count_triplets_1', () => {
934
it('countTriplets test cases', () => {

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.js

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

4-
import CountTriplets from './count_triplets_1_optmized.js';
5-
import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';
6-
import BIG_TEST_CASES from './count_triplets_1.big.testcases.json';
4+
import { countTriplets } from './count_triplets_1_optmized.js';
5+
import SMALL_TEST_CASES from './count_triplets_1_testcases.json';
6+
7+
const BIG_TEST_CASES = [
8+
{
9+
title: 'Sample Test Case 2',
10+
input: [
11+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
12+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
13+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
14+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
15+
],
16+
r: 1,
17+
expected: 161700
18+
}
19+
];
720

821
describe('count_triplets_1 (optimized)', () => {
922
it('countTriplets small test cases', () => {
1023
expect.assertions(4);
1124

1225
SMALL_TEST_CASES.forEach((test) => {
13-
const answer = CountTriplets.countTriplets(test.input, test.r);
26+
const answer = countTriplets(test.input, test.r);
1427

1528
console.debug(
1629
`countTriplets(${test.input}, ${test.r}) solution found: ${answer}`
@@ -24,7 +37,7 @@ describe('count_triplets_1 (optimized)', () => {
2437
expect.assertions(1);
2538

2639
BIG_TEST_CASES.forEach((test) => {
27-
const answer = CountTriplets.countTriplets(test.input, test.r);
40+
const answer = countTriplets(test.input, test.r);
2841

2942
console.debug(
3043
`countTriplets(${test.input}, ${test.r}) solution found: ${answer}`

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @see Solution Notes: [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1-solution-notes.md]]
44
*/
55

6-
function countTriplets(arr, ratio) {
6+
export function countTriplets(arr, ratio) {
77
let triplets = 0;
88

99
const aCounter = arr.reduce((accumulator, entry) => {

0 commit comments

Comments
 (0)