Skip to content

Commit 93169fa

Browse files
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and Hashmaps: Two Strings.
* TEST data moved to JSON. * Adjusted the interface to match what hackerrank expects.
1 parent eafe115 commit 93169fa

File tree

3 files changed

+63
-63
lines changed

3 files changed

+63
-63
lines changed

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const __YES__ = 'YES';
66
const __NO__ = 'NO';
77

8-
export function twoStringsCompute(s1, s2) {
8+
function twoStringsCompute(s1, s2) {
99
for (const char of s1) {
1010
if (s2.includes(char)) {
1111
return true;
@@ -14,7 +14,7 @@ export function twoStringsCompute(s1, s2) {
1414
return false;
1515
}
1616

17-
export function twoStrings(s1, s2) {
17+
function twoStrings(s1, s2) {
1818
return twoStringsCompute(s1, s2) ? __YES__ : __NO__;
1919
}
2020

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

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

4-
import { twoStrings } from './two_strings.js';
5-
6-
const TEST_CASES = [
7-
{
8-
title: 'Example 1 and 2',
9-
comparing: [
10-
{
11-
s1: 'and',
12-
s2: 'art',
13-
expected: 'YES'
14-
},
15-
{
16-
s1: 'be',
17-
s2: 'cat',
18-
expected: 'NO'
19-
}
20-
]
21-
},
22-
{
23-
title: 'Sample Test Case 0',
24-
comparing: [
25-
{
26-
s1: 'hello',
27-
s2: 'world',
28-
expected: 'YES'
29-
},
30-
{
31-
s1: 'hi',
32-
s2: 'world',
33-
expected: 'NO'
34-
}
35-
]
36-
},
37-
{
38-
title: 'Sample Test Case 6',
39-
comparing: [
40-
{
41-
s1: 'wouldyoulikefries',
42-
s2: 'abcabcabcabcabcabc',
43-
expected: 'NO'
44-
},
45-
{
46-
s1: 'hackerrankcommunity',
47-
s2: 'cdecdecdecde',
48-
expected: 'YES'
49-
},
50-
{
51-
s1: 'jackandjill',
52-
s2: 'wentupthehill',
53-
expected: 'YES'
54-
},
55-
{
56-
s1: 'writetoyourparents',
57-
s2: 'fghmqzldbc',
58-
expected: 'NO'
59-
}
60-
]
61-
}
62-
];
4+
import twoStrings from './two_strings.js';
5+
import TEST_CASES from './two_strings.testcases.json';
636

647
describe('two_strings', () => {
658
it('twoStrings test cases', () => {
669
expect.assertions(8);
6710

6811
TEST_CASES.forEach((testCase) => {
69-
testCase.comparing.forEach((test) => {
70-
const answer = twoStrings(test.s1, test.s2);
12+
testCase.tests.forEach((test) => {
13+
const answer = twoStrings.twoStrings(test.s1, test.s2);
7114

7215
console.debug(
7316
`twoStrings(${test.s1}, ${test.s2}) solution found: ${answer}`
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[
2+
{
3+
"title": "Example 1 and 2",
4+
"tests": [
5+
{
6+
"s1": "and",
7+
"s2": "art",
8+
"expected": "YES"
9+
},
10+
{
11+
"s1": "be",
12+
"s2": "cat",
13+
"expected": "NO"
14+
}
15+
]
16+
},
17+
{
18+
"title": "Sample Test Case 0",
19+
"tests": [
20+
{
21+
"s1": "hello",
22+
"s2": "world",
23+
"expected": "YES"
24+
},
25+
{
26+
"s1": "hi",
27+
"s2": "world",
28+
"expected": "NO"
29+
}
30+
]
31+
},
32+
{
33+
"title": "Sample Test Case 6",
34+
"tests": [
35+
{
36+
"s1": "wouldyoulikefries",
37+
"s2": "abcabcabcabcabcabc",
38+
"expected": "NO"
39+
},
40+
{
41+
"s1": "hackerrankcommunity",
42+
"s2": "cdecdecdecde",
43+
"expected": "YES"
44+
},
45+
{
46+
"s1": "jackandjill",
47+
"s2": "wentupthehill",
48+
"expected": "YES"
49+
},
50+
{
51+
"s1": "writetoyourparents",
52+
"s2": "fghmqzldbc",
53+
"expected": "NO"
54+
}
55+
]
56+
}
57+
]

0 commit comments

Comments
 (0)