diff --git a/src/hackerrank/implementation/betweenTwoSets.js b/src/hackerrank/implementation/betweenTwoSets.js index 91b54d65..0b7dcde7 100644 --- a/src/hackerrank/implementation/betweenTwoSets.js +++ b/src/hackerrank/implementation/betweenTwoSets.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/implementation/betweenTwoSets.md]] */ -export function isFactor(n, group) { +function isFactor(n, group) { let result = true; let i = 0; @@ -19,7 +19,7 @@ export function isFactor(n, group) { return result; } -export function factorOf(n, group) { +function factorOf(n, group) { let result = true; let i = 0; @@ -36,7 +36,7 @@ export function factorOf(n, group) { return result; } -export function getTotalX(a, b) { +function getTotalX(a, b) { let max = 0; for (const j of b) { if (j > max) max = j; @@ -53,4 +53,5 @@ export function getTotalX(a, b) { return result.length; } -export default { getTotalX }; +export default { getTotalX, isFactor, factorOf }; +export { getTotalX, isFactor, factorOf }; diff --git a/src/hackerrank/implementation/birthday.js b/src/hackerrank/implementation/birthday.js index 759f3027..aa047fbe 100644 --- a/src/hackerrank/implementation/birthday.js +++ b/src/hackerrank/implementation/birthday.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function birthday(s, d, m) { +function birthday(s, d, m) { let result = 0; console.debug(`s: ${s}`); @@ -23,3 +23,4 @@ export function birthday(s, d, m) { } export default { birthday }; +export { birthday }; diff --git a/src/hackerrank/implementation/bonAppetit.js b/src/hackerrank/implementation/bonAppetit.js index 7cfcc78e..8d897509 100644 --- a/src/hackerrank/implementation/bonAppetit.js +++ b/src/hackerrank/implementation/bonAppetit.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function bonAppetit(bill, k, b) { +function bonAppetit(bill, k, b) { const totalSum = bill.reduce( (previousValue, currentValue) => previousValue + currentValue, 0 @@ -25,3 +25,4 @@ export function bonAppetit(bill, k, b) { } export default { bonAppetit }; +export { bonAppetit }; diff --git a/src/hackerrank/implementation/breakingRecords.js b/src/hackerrank/implementation/breakingRecords.js index 5c536e65..0766d4f2 100644 --- a/src/hackerrank/implementation/breakingRecords.js +++ b/src/hackerrank/implementation/breakingRecords.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/implementation/breakingRecords.md]] */ -export function breakingRecords(scores) { +function breakingRecords(scores) { if (scores.length === 0) { throw new Error('Empty input'); } @@ -29,3 +29,4 @@ export function breakingRecords(scores) { } export default { breakingRecords }; +export { breakingRecords }; diff --git a/src/hackerrank/implementation/countApplesAndOranges.js b/src/hackerrank/implementation/countApplesAndOranges.js index 2dfe652d..e30960f7 100644 --- a/src/hackerrank/implementation/countApplesAndOranges.js +++ b/src/hackerrank/implementation/countApplesAndOranges.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/implementation/countApplesAndOranges.md]] */ -export function countApplesAndOranges(s, t, a, b, apples, oranges) { +function countApplesAndOranges(s, t, a, b, apples, oranges) { let cApples = 0; let cOranges = 0; @@ -26,3 +26,4 @@ export function countApplesAndOranges(s, t, a, b, apples, oranges) { } export default { countApplesAndOranges }; +export { countApplesAndOranges }; diff --git a/src/hackerrank/implementation/countingValleys.js b/src/hackerrank/implementation/countingValleys.js index e8dab3fe..d327553b 100644 --- a/src/hackerrank/implementation/countingValleys.js +++ b/src/hackerrank/implementation/countingValleys.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function countingValleys(steps, path) { +function countingValleys(steps, path) { const stepList = path.split(''); let altitude = 0; let valleys = 0; @@ -27,3 +27,4 @@ export function countingValleys(steps, path) { } export default { countingValleys }; +export { countingValleys }; diff --git a/src/hackerrank/implementation/dayOfProgrammer.js b/src/hackerrank/implementation/dayOfProgrammer.js index 5f68628f..db976797 100644 --- a/src/hackerrank/implementation/dayOfProgrammer.js +++ b/src/hackerrank/implementation/dayOfProgrammer.js @@ -7,7 +7,7 @@ import { daysInMonthNumber } from '../../constants/index.js'; const zeroPad = (num, places) => String(num).padStart(places, '0'); -export function dayOfProgrammer(year) { +function dayOfProgrammer(year) { const dayToSearch = 256; let leap; @@ -51,3 +51,4 @@ export function dayOfProgrammer(year) { } export default { dayOfProgrammer }; +export { dayOfProgrammer }; diff --git a/src/hackerrank/implementation/divisibleSumPairs.js b/src/hackerrank/implementation/divisibleSumPairs.js index 3a055ca2..4ae64280 100644 --- a/src/hackerrank/implementation/divisibleSumPairs.js +++ b/src/hackerrank/implementation/divisibleSumPairs.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function divisibleSumPairs(n, k, ar) { +function divisibleSumPairs(n, k, ar) { let pairs = 0; for (let i = 0; i < ar.length; i++) { for (let j = i + 1; j < ar.length; j++) { @@ -19,3 +19,4 @@ export function divisibleSumPairs(n, k, ar) { } export default { divisibleSumPairs }; +export { divisibleSumPairs }; diff --git a/src/hackerrank/implementation/gradingStudents.js b/src/hackerrank/implementation/gradingStudents.js index 0e8a4cee..9985fe5f 100644 --- a/src/hackerrank/implementation/gradingStudents.js +++ b/src/hackerrank/implementation/gradingStudents.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/implementation/gradingStudents.md]] */ -export function gradingStudents(grades) { +function gradingStudents(grades) { const minimum = 38; const roundTo = 5; const result = []; @@ -23,3 +23,4 @@ export function gradingStudents(grades) { } export default { gradingStudents }; +export { gradingStudents }; diff --git a/src/hackerrank/implementation/jumpingOnClouds.js b/src/hackerrank/implementation/jumpingOnClouds.js index 5411405d..6709387e 100644 --- a/src/hackerrank/implementation/jumpingOnClouds.js +++ b/src/hackerrank/implementation/jumpingOnClouds.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function jumpingOnClouds(c) { +function jumpingOnClouds(c) { let result = 0; let key = 0; @@ -26,3 +26,4 @@ export function jumpingOnClouds(c) { } export default { jumpingOnClouds }; +export { jumpingOnClouds }; diff --git a/src/hackerrank/implementation/kangaroo.js b/src/hackerrank/implementation/kangaroo.js index 9b304d49..36293077 100644 --- a/src/hackerrank/implementation/kangaroo.js +++ b/src/hackerrank/implementation/kangaroo.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/implementation/kangaroo.md]] */ -export function kangaroo(x1, v1, x2, v2) { +function kangaroo(x1, v1, x2, v2) { if (v1 === v2) { if (x1 !== x2) return 'NO'; return 'YES'; @@ -18,3 +18,4 @@ export function kangaroo(x1, v1, x2, v2) { } export default { kangaroo }; +export { kangaroo }; diff --git a/src/hackerrank/implementation/migratoryBirds.js b/src/hackerrank/implementation/migratoryBirds.js index 611ad8dd..0e4be156 100644 --- a/src/hackerrank/implementation/migratoryBirds.js +++ b/src/hackerrank/implementation/migratoryBirds.js @@ -5,7 +5,7 @@ import util from 'util'; import { logger as console } from '../../logger.js'; -export function migratoryBirds(arr) { +function migratoryBirds(arr) { if (arr.length === 0) { throw new Error('Empty input'); } @@ -35,3 +35,4 @@ export function migratoryBirds(arr) { } export default { migratoryBirds }; +export { migratoryBirds }; diff --git a/src/hackerrank/implementation/minimumAbsoluteDifference.js b/src/hackerrank/implementation/minimumAbsoluteDifference.js index f082d68d..8691f55a 100644 --- a/src/hackerrank/implementation/minimumAbsoluteDifference.js +++ b/src/hackerrank/implementation/minimumAbsoluteDifference.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function minimumAbsoluteDifference(arr) { +function minimumAbsoluteDifference(arr) { if (arr.length === 0) { throw new Error('Empty input'); } @@ -31,3 +31,4 @@ export function minimumAbsoluteDifference(arr) { } export default { minimumAbsoluteDifference }; +export { minimumAbsoluteDifference }; diff --git a/src/hackerrank/implementation/repeatedString.js b/src/hackerrank/implementation/repeatedString.js index cdda9d65..71e92e81 100644 --- a/src/hackerrank/implementation/repeatedString.js +++ b/src/hackerrank/implementation/repeatedString.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function countAs(word) { +function countAs(word) { let result = 0; const chars = word.split(''); @@ -18,7 +18,7 @@ export function countAs(word) { return result; } -export function repeatedString(s, n) { +function repeatedString(s, n) { let result = 0; const blockSize = s.length; @@ -32,4 +32,5 @@ export function repeatedString(s, n) { return result; } -export default { countAs }; +export default { repeatedString }; +export { repeatedString }; diff --git a/src/hackerrank/implementation/sockMerchant.js b/src/hackerrank/implementation/sockMerchant.js index 8ce56c54..9fd4fe5f 100644 --- a/src/hackerrank/implementation/sockMerchant.js +++ b/src/hackerrank/implementation/sockMerchant.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function sockMerchant(n, ar) { +function sockMerchant(n, ar) { let result = 0; const matches = {}; @@ -25,3 +25,4 @@ export function sockMerchant(n, ar) { } export default { sockMerchant }; +export { sockMerchant }; diff --git a/src/hackerrank/interview_preparation_kit/arrays/2d_array.js b/src/hackerrank/interview_preparation_kit/arrays/2d_array.js index d6474676..6a2b8cb3 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/2d_array.js +++ b/src/hackerrank/interview_preparation_kit/arrays/2d_array.js @@ -58,3 +58,4 @@ function hourglassSum(arr) { } export default { hourglassSum }; +export { hourglassSum }; diff --git a/src/hackerrank/interview_preparation_kit/arrays/2d_array.test.js b/src/hackerrank/interview_preparation_kit/arrays/2d_array.test.js index c15f0072..c3f995e4 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/2d_array.test.js +++ b/src/hackerrank/interview_preparation_kit/arrays/2d_array.test.js @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger.js'; -import twoDArray from './2d_array.js'; +import { hourglassSum } from './2d_array.js'; import TEST_CASES from './2d_array.testcases_test.json'; describe('arrays: 2d Array hourglassSum', () => { @@ -9,7 +9,7 @@ describe('arrays: 2d Array hourglassSum', () => { expect.assertions(3); TEST_CASES.forEach((test) => { - const answer = twoDArray.hourglassSum(test.input); + const answer = hourglassSum(test.input); console.debug( `gethourGlass(${test.input.toString()}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.js b/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.js index fcd6ddfb..de72d674 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.js +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.js @@ -29,3 +29,4 @@ function arrayManipulation(n, queries) { } export default { arrayManipulation }; +export { arrayManipulation }; diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.js b/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.js index 6b43b49c..57af871c 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.js +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.js @@ -3,14 +3,14 @@ import { logger as console } from '../../../logger.js'; import TEST_CASES from './cruch_testcases_test.json'; -import crush from './cruch_bruteforce.js'; +import { arrayManipulation } from './cruch_bruteforce.js'; describe('arrays: crush (bruteforce) small cases', () => { it('arrayManipulation Test Cases', () => { expect.assertions(3); TEST_CASES.forEach((test) => { - const answer = crush.arrayManipulation(test.n, test.queries); + const answer = arrayManipulation(test.n, test.queries); console.debug( `arrayManipulation(${test.n}, ${test.queries}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.js b/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.js index fe27e72d..dcb32065 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.js +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.js @@ -29,3 +29,4 @@ function arrayManipulation(n, queries) { } export default { arrayManipulation }; +export { arrayManipulation }; diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.js b/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.js index 42f52835..f1bd9e86 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.js +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.js @@ -3,14 +3,14 @@ import { logger as console } from '../../../logger.js'; import TEST_CASES from './cruch_testcases_test.json'; -import crush from './cruch_optimized.js'; +import { arrayManipulation } from './cruch_optimized.js'; describe('arrays: crush (optimized)', () => { it('arrayManipulation Test Cases', () => { expect.assertions(3); TEST_CASES.forEach((test) => { - const answer = crush.arrayManipulation(test.n, test.queries); + const answer = arrayManipulation(test.n, test.queries); console.debug( `arrayManipulation(${test.n}, ${test.queries}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.js b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.js index 1890424c..7dd68e91 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.js +++ b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md]] */ -export function rotLeftOne(aNumbers) { +function rotLeftOne(aNumbers) { const first = aNumbers.shift(); if (first !== undefined) { aNumbers.push(first); @@ -11,7 +11,7 @@ export function rotLeftOne(aNumbers) { return aNumbers; } -export function rotLeft(aNumbers, dRotations) { +function rotLeft(aNumbers, dRotations) { let output = [...aNumbers]; for (let i = 0; i < dRotations; i++) { @@ -22,3 +22,4 @@ export function rotLeft(aNumbers, dRotations) { } export default { rotLeft, rotLeftOne }; +export { rotLeft }; diff --git a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.js b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.js index 8a66a45a..199cc9e2 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.js +++ b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.js @@ -1,42 +1,20 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger.js'; -import { rotLeft, rotLeftOne } from './ctci_array_left_rotation.js'; +import { rotLeft } from './ctci_array_left_rotation.js'; -const ROT_LEFT_ONE_TEST_CASES = [ - { numbers: [1, 2, 3, 4, 5], expected: [2, 3, 4, 5, 1] }, - { numbers: [2, 3, 4, 5, 1], expected: [3, 4, 5, 1, 2] }, - { numbers: [3, 4, 5, 1, 2], expected: [4, 5, 1, 2, 3] }, - { numbers: [4, 5, 1, 2, 3], expected: [5, 1, 2, 3, 4] }, - { numbers: [5, 1, 2, 3, 4], expected: [1, 2, 3, 4, 5] } -]; - -const ROT_LEFT_TEST_CASES = [ - { numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] } -]; +import ROT_LEFT_TEST_CASES from './ctci_array_left_rotation.testcases.json'; describe('ctci_array_left_rotation', () => { - it('rotLeftOne Test Cases', () => { - expect.assertions(5); - - ROT_LEFT_ONE_TEST_CASES.forEach((value) => { - const answer = rotLeftOne(value.numbers); - - console.debug(`rotLeftOne(${value.numbers}) solution found: ${answer}`); - - expect(answer).toStrictEqual(value.expected); - }); - }); - it('rotLeft Test cases', () => { - expect.assertions(1); + expect.assertions(8); - ROT_LEFT_TEST_CASES.forEach((value) => { - const answer = rotLeft(value.numbers, value.d_rotations); + ROT_LEFT_TEST_CASES.forEach((test) => { + const answer = rotLeft(test.input, test.d_rotations); - console.debug(`rotLeft(${value.numbers}) solution found: ${answer}`); + console.debug(`rotLeft(${test.numbers}) solution found: ${answer}`); - expect(answer).toStrictEqual(value.expected); + expect(answer).toStrictEqual(test.expected); }); }); }); diff --git a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json new file mode 100644 index 00000000..d78f6838 --- /dev/null +++ b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json @@ -0,0 +1,10 @@ +[ + {"title": "Own 0", "input": [1, 2, 3, 4, 5], "d_rotations": 1, "expected": [2, 3, 4, 5, 1]}, + {"title": "Own 1", "input": [2, 3, 4, 5, 1], "d_rotations": 1, "expected": [3, 4, 5, 1, 2]}, + {"title": "Own 2", "input": [3, 4, 5, 1, 2], "d_rotations": 1, "expected": [4, 5, 1, 2, 3]}, + {"title": "Own 3", "input": [4, 5, 1, 2, 3], "d_rotations": 1, "expected": [5, 1, 2, 3, 4]}, + {"title": "Own 4", "input": [5, 1, 2, 3, 4], "d_rotations": 1, "expected": [1, 2, 3, 4, 5]}, + {"title": "Sample Test case 0", "input": [1, 2, 3, 4, 5], "d_rotations": 4, "expected": [5, 1, 2, 3, 4]}, + {"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]}, + {"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]} +] diff --git a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.js b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.js index 71d1a341..de3cb7d0 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.js +++ b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.md]] */ -export function minimumSwaps(arr) { +function minimumSwaps(arr) { const indexedGroup = arr.map((x) => x - 1); let swaps = 0; let index = 0; @@ -23,3 +23,4 @@ export function minimumSwaps(arr) { } export default { minimumSwaps }; +export { minimumSwaps }; diff --git a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.test.js b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.test.js index 9c784a32..7051d749 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.test.js +++ b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.test.js @@ -3,11 +3,7 @@ import { logger as console } from '../../../logger.js'; import { minimumSwaps } from './minimum_swaps_2.js'; -const TEST_CASES = [ - { title: 'Sample input 0', input: [4, 3, 1, 2], expected: 3 }, - { title: 'Sample input 1', input: [2, 3, 4, 1, 5], expected: 3 }, - { title: 'Sample input 2', input: [1, 3, 5, 2, 4, 6, 7], expected: 3 } -]; +import TEST_CASES from './minimum_swaps_2.testcases.json'; describe('minimum swaps 2', () => { it('minimumSwaps', () => { diff --git a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.testcases.json b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.testcases.json new file mode 100644 index 00000000..6a814023 --- /dev/null +++ b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.testcases.json @@ -0,0 +1,5 @@ +[ + {"title": "Sample input 0", "input": [4, 3, 1, 2], "expected": 3}, + {"title": "Sample input 1", "input": [2, 3, 4, 1, 5], "expected": 3}, + {"title": "Sample input 2", "input": [1, 3, 5, 2, 4, 6, 7], "expected": 3} +] diff --git a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.js b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.js index 06d53d1d..e1328a7a 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.js +++ b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.js @@ -49,3 +49,10 @@ export default { minimumBribesText, TOO_CHAOTIC_ERROR }; + +export { + minimumBribes, + minimumBribesCalculate, + minimumBribesText, + TOO_CHAOTIC_ERROR +}; diff --git a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.js b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.js index 5041126b..00bca3bd 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.js +++ b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.js @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger.js'; -import testingModule from './new_year_chaos.js'; +import { minimumBribes, minimumBribesText } from './new_year_chaos.js'; import TEST_CASES from './new_year_chaos.testcases.json'; @@ -10,8 +10,8 @@ describe('new_year_chaos', () => { expect.assertions(5); TEST_CASES.forEach((test) => { - const answer = testingModule.minimumBribesText(test.input); - testingModule.minimumBribes(test.input); + const answer = minimumBribesText(test.input); + minimumBribes(test.input); console.debug( `minimumBribesText(${test.input}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1.big.testcases.json b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1.big.testcases.json new file mode 100644 index 00000000..f38639cd --- /dev/null +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1.big.testcases.json @@ -0,0 +1,12 @@ +[ + { + "title": "Sample Test Case 2", + "input": [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, 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, 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, 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], + "r": 1, + "expected": 161700 + } +] diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_testcases.json b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1.small.testcases.json similarity index 100% rename from src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_testcases.json rename to src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1.small.testcases.json diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.js index edca0608..26a080d0 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.js @@ -4,7 +4,7 @@ */ import { logger as console } from '../../../logger.js'; -export function countTriplets(arr, ratio) { +function countTriplets(arr, ratio) { const size = arr.length; let counter = 0; @@ -24,3 +24,4 @@ export function countTriplets(arr, ratio) { } export default { countTriplets }; +export { countTriplets }; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.js index 590330ef..264aea24 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.js @@ -3,32 +3,7 @@ import { logger as console } from '../../../logger.js'; import { countTriplets } from './count_triplets_1_bruteforce.js'; -const SMALL_TEST_CASES = [ - { - title: 'Sample Test Case 0', - input: [1, 2, 2, 4], - r: 2, - expected: 2 - }, - { - title: 'Sample Test Case 1', - input: [1, 3, 9, 9, 27, 81], - r: 3, - expected: 6 - }, - { - title: 'Sample Test Case 1 (unsorted)', - input: [9, 3, 1, 81, 9, 27], - r: 3, - expected: 1 - }, - { - title: 'Sample Test Case 12', - input: [1, 5, 5, 25, 125], - r: 5, - expected: 4 - } -]; +import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json'; describe('count_triplets_1', () => { it('countTriplets test cases', () => { diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.js index 78890b9e..c65ca669 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.js @@ -2,21 +2,8 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger.js'; import { countTriplets } from './count_triplets_1_optmized.js'; -import SMALL_TEST_CASES from './count_triplets_1_testcases.json'; - -const BIG_TEST_CASES = [ - { - title: 'Sample Test Case 2', - input: [ - 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, - 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, - 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, - 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 - ], - r: 1, - expected: 161700 - } -]; +import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json'; +import BIG_TEST_CASES from './count_triplets_1.big.testcases.json'; describe('count_triplets_1 (optimized)', () => { it('countTriplets small test cases', () => { diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.js index bef443a1..28a08ecb 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.js @@ -3,7 +3,7 @@ * @see Solution Notes: [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1-solution-notes.md]] */ -export function countTriplets(arr, ratio) { +function countTriplets(arr, ratio) { let triplets = 0; const aCounter = arr.reduce((accumulator, entry) => { @@ -36,3 +36,4 @@ export function countTriplets(arr, ratio) { } export default { countTriplets }; +export { countTriplets }; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.js index 2ad2e791..7bfaa1ba 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.js @@ -5,7 +5,7 @@ const __YES__ = 'Yes'; const __NO__ = 'No'; -export function checkMagazineCompute(magazine, note) { +function checkMagazineCompute(magazine, note) { const dictionary = {}; for (const word of magazine) { @@ -27,8 +27,13 @@ export function checkMagazineCompute(magazine, note) { return true; } -export function checkMagazine(magazine, note) { +function checkMagazineText(magazine, note) { return checkMagazineCompute(magazine, note) ? __YES__ : __NO__; } -export default { checkMagazine }; +function checkMagazine(magazine, note) { + console.log(checkMagazineCompute(magazine, note) ? __YES__ : __NO__); +} + +export default { checkMagazine, checkMagazineText }; +export { checkMagazine, checkMagazineText }; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.test.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.test.js index 5e7aaa59..b25782bd 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.test.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.test.js @@ -1,35 +1,16 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger.js'; -import { checkMagazine } from './ctci-ransom-note.js'; - -const TEST_CASES = [ - { - title: 'Sample Test Case 0', - magazine: ['give', 'me', 'one', 'grand', 'today', 'night'], - note: ['give', 'one', 'grand', 'today'], - expected: 'Yes' - }, - { - title: 'Sample Test Case 1', - magazine: ['two', 'times', 'three', 'is', 'not', 'four'], - note: ['two', 'times', 'two', 'is', 'four'], - expected: 'No' - }, - { - title: 'Sample Test', - magazine: ['two', 'two', 'times', 'three', 'is', 'not', 'four'], - note: ['two', 'times', 'two', 'is', 'four'], - expected: 'Yes' - } -]; +import { checkMagazine, checkMagazineText } from './ctci-ransom-note.js'; +import TEST_CASES from './ctci-ransom-note.testcases.json'; describe('ctci_ransom_note', () => { it('checkMagazine test cases', () => { expect.assertions(3); TEST_CASES.forEach((value) => { - const answer = checkMagazine(value.magazine, value.note); + const answer = checkMagazineText(value.magazine, value.note); + checkMagazine(value.magazine, value.note); console.debug( `checkMagazine(${value.magazine}, ${value.note}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.testcases.json b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.testcases.json new file mode 100644 index 00000000..8f04948f --- /dev/null +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.testcases.json @@ -0,0 +1,20 @@ +[ + { + "title": "Sample Test Case 0", + "magazine": ["give", "me", "one", "grand", "today", "night"], + "note": ["give", "one", "grand", "today"], + "expected": "Yes" + }, + { + "title": "Sample Test Case 1", + "magazine": ["two", "times", "three", "is", "not", "four"], + "note": ["two", "times", "two", "is", "four"], + "expected": "No" + }, + { + "title": "Sample Test", + "magazine": ["two", "two", "times", "three", "is", "not", "four"], + "note": ["two", "times", "two", "is", "four"], + "expected": "Yes" + } +] diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_bruteforce.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_bruteforce.js index 97612098..f9ec89a7 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_bruteforce.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_bruteforce.js @@ -3,7 +3,7 @@ * @see Solution Notes: [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency-queries-solution-notes.md]] */ -export function freqQuery(queries) { +function freqQuery(queries) { const result = []; const dataMap = {}; @@ -45,3 +45,4 @@ export function freqQuery(queries) { } export default { freqQuery }; +export { freqQuery }; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_optimized.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_optimized.js index c95fceb9..f052db31 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_optimized.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_optimized.js @@ -3,7 +3,7 @@ * @see Solution Notes: [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency-queries-solution-notes.md]] */ -export function updateFrequency(frequencyMap, data, currentFreq, newFreq) { +function updateFrequency(frequencyMap, data, currentFreq, newFreq) { const freqMap = frequencyMap; if (newFreq > 0) { @@ -25,7 +25,7 @@ export function updateFrequency(frequencyMap, data, currentFreq, newFreq) { return freqMap; } -export function freqQuery(queries) { +function freqQuery(queries) { const result = []; const dataMap = {}; const freqMap = {}; @@ -81,3 +81,4 @@ export function freqQuery(queries) { } export default { freqQuery }; +export { freqQuery }; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/sherlock_and_anagrams.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/sherlock_and_anagrams.js index a96c3f9f..ae99e7d0 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/sherlock_and_anagrams.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/sherlock_and_anagrams.js @@ -10,7 +10,7 @@ function extraLongFactorials(n) { return rs; } -export function sherlockAndAnagrams(s) { +function sherlockAndAnagrams(s) { const candidates = {}; const size = s.length; @@ -66,3 +66,4 @@ export function sherlockAndAnagrams(s) { } export default { sherlockAndAnagrams }; +export { sherlockAndAnagrams }; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.js index 387ff39d..4ba37217 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.js @@ -5,7 +5,7 @@ const __YES__ = 'YES'; const __NO__ = 'NO'; -export function twoStringsCompute(s1, s2) { +function twoStringsCompute(s1, s2) { for (const char of s1) { if (s2.includes(char)) { return true; @@ -14,8 +14,9 @@ export function twoStringsCompute(s1, s2) { return false; } -export function twoStrings(s1, s2) { +function twoStrings(s1, s2) { return twoStringsCompute(s1, s2) ? __YES__ : __NO__; } export default { twoStrings }; +export { twoStrings }; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.test.js b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.test.js index 23e95061..f4699a05 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.test.js +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.test.js @@ -2,71 +2,14 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger.js'; import { twoStrings } from './two_strings.js'; - -const TEST_CASES = [ - { - title: 'Example 1 and 2', - comparing: [ - { - s1: 'and', - s2: 'art', - expected: 'YES' - }, - { - s1: 'be', - s2: 'cat', - expected: 'NO' - } - ] - }, - { - title: 'Sample Test Case 0', - comparing: [ - { - s1: 'hello', - s2: 'world', - expected: 'YES' - }, - { - s1: 'hi', - s2: 'world', - expected: 'NO' - } - ] - }, - { - title: 'Sample Test Case 6', - comparing: [ - { - s1: 'wouldyoulikefries', - s2: 'abcabcabcabcabcabc', - expected: 'NO' - }, - { - s1: 'hackerrankcommunity', - s2: 'cdecdecdecde', - expected: 'YES' - }, - { - s1: 'jackandjill', - s2: 'wentupthehill', - expected: 'YES' - }, - { - s1: 'writetoyourparents', - s2: 'fghmqzldbc', - expected: 'NO' - } - ] - } -]; +import TEST_CASES from './two_strings.testcases.json'; describe('two_strings', () => { it('twoStrings test cases', () => { expect.assertions(8); TEST_CASES.forEach((testCase) => { - testCase.comparing.forEach((test) => { + testCase.tests.forEach((test) => { const answer = twoStrings(test.s1, test.s2); console.debug( diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.testcases.json b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.testcases.json new file mode 100644 index 00000000..2d4411b7 --- /dev/null +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.testcases.json @@ -0,0 +1,57 @@ +[ + { + "title": "Example 1 and 2", + "tests": [ + { + "s1": "and", + "s2": "art", + "expected": "YES" + }, + { + "s1": "be", + "s2": "cat", + "expected": "NO" + } + ] + }, + { + "title": "Sample Test Case 0", + "tests": [ + { + "s1": "hello", + "s2": "world", + "expected": "YES" + }, + { + "s1": "hi", + "s2": "world", + "expected": "NO" + } + ] + }, + { + "title": "Sample Test Case 6", + "tests": [ + { + "s1": "wouldyoulikefries", + "s2": "abcabcabcabcabcabc", + "expected": "NO" + }, + { + "s1": "hackerrankcommunity", + "s2": "cdecdecdecde", + "expected": "YES" + }, + { + "s1": "jackandjill", + "s2": "wentupthehill", + "expected": "YES" + }, + { + "s1": "writetoyourparents", + "s2": "fghmqzldbc", + "expected": "NO" + } + ] + } +] diff --git a/src/hackerrank/interview_preparation_kit/dynamic_programming/max_array_sum.js b/src/hackerrank/interview_preparation_kit/dynamic_programming/max_array_sum.js index 25403b31..4b2e49ac 100644 --- a/src/hackerrank/interview_preparation_kit/dynamic_programming/max_array_sum.js +++ b/src/hackerrank/interview_preparation_kit/dynamic_programming/max_array_sum.js @@ -6,7 +6,7 @@ const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m), BigInt(0)); -export function maxSubsetSum(arr) { +function maxSubsetSum(arr) { const arrCopy = arr.map((x) => BigInt(x)); if (arrCopy.length === 0) { @@ -32,3 +32,4 @@ export function maxSubsetSum(arr) { } export default { maxSubsetSum }; +export { maxSubsetSum }; diff --git a/src/hackerrank/interview_preparation_kit/greedy_algorithms/angry_children.js b/src/hackerrank/interview_preparation_kit/greedy_algorithms/angry_children.js index d0120d0e..14bf0ed1 100644 --- a/src/hackerrank/interview_preparation_kit/greedy_algorithms/angry_children.js +++ b/src/hackerrank/interview_preparation_kit/greedy_algorithms/angry_children.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/greedy_algorithms/angry-children.md]] */ -export function maxMin(k, arr) { +function maxMin(k, arr) { const sortedlist = arr.map((x) => x).sort((a, b) => a - b); let result = sortedlist[sortedlist.length - 1] - sortedlist[0]; @@ -17,3 +17,4 @@ export function maxMin(k, arr) { } export default { maxMin }; +export { maxMin }; diff --git a/src/hackerrank/interview_preparation_kit/greedy_algorithms/greedy_florist.js b/src/hackerrank/interview_preparation_kit/greedy_algorithms/greedy_florist.js index de098bed..ff3d8473 100644 --- a/src/hackerrank/interview_preparation_kit/greedy_algorithms/greedy_florist.js +++ b/src/hackerrank/interview_preparation_kit/greedy_algorithms/greedy_florist.js @@ -3,7 +3,7 @@ * @see Solution Notes: [[docs/hackerrank/interview_preparation_kit/greedy_algorithms/greedy-florist-solution-notes.md]] */ -export function getMinimumCost(k, c) { +function getMinimumCost(k, c) { const flowers = c.map((x) => x).sort((a, b) => b - a); let total = 0; @@ -20,3 +20,4 @@ export function getMinimumCost(k, c) { } export default { getMinimumCost }; +export { getMinimumCost }; diff --git a/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.js b/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.js index 6ee80d19..200fe06f 100644 --- a/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.js +++ b/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.js @@ -39,7 +39,7 @@ class Contest { } } -export function luckBalance(k, contests) { +function luckBalance(k, contests) { let importantContests = []; const nonimportantContests = []; @@ -78,3 +78,4 @@ export function luckBalance(k, contests) { } export default { luckBalance }; +export { luckBalance }; diff --git a/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.test.js b/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.test.js index 9f3f776c..8d021ed0 100644 --- a/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.test.js +++ b/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.test.js @@ -3,48 +3,7 @@ import { logger as console } from '../../../logger.js'; import { luckBalance } from './luck-balance.js'; -const TEST_CASES = [ - { - 'title': 'Sample Test case 0', - 'k': 3, - 'contests': [ - [5, 1], - [2, 1], - [1, 1], - [8, 1], - [10, 0], - [5, 0] - ], - 'expected': 29 - }, - { - 'title': 'Sample Test case 1', - 'k': 5, - 'contests': [ - [13, 1], - [10, 1], - [9, 1], - [8, 1], - [13, 1], - [12, 1], - [18, 1], - [13, 1] - ], - 'expected': 42 - }, - { - 'title': 'Sample Test case 1', - 'k': 2, - 'contests': [ - [5, 1], - [4, 0], - [6, 1], - [2, 1], - [8, 0] - ], - 'expected': 21 - } -]; +import TEST_CASES from './luck-balance.testcases.json'; describe('luck-balance', () => { it('luckBalance test cases', () => { diff --git a/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.testcases.json b/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.testcases.json new file mode 100644 index 00000000..d0777d48 --- /dev/null +++ b/src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.testcases.json @@ -0,0 +1,42 @@ +[ + { + "title": "Sample Test case 0", + "k": 3, + "contests": [ + [5, 1], + [2, 1], + [1, 1], + [8, 1], + [10, 0], + [5, 0] + ], + "expected": 29 + }, + { + "title": "Sample Test case 1", + "k": 5, + "contests": [ + [13, 1], + [10, 1], + [9, 1], + [8, 1], + [13, 1], + [12, 1], + [18, 1], + [13, 1] + ], + "expected": 42 + }, + { + "title": "Sample Test case 1", + "k": 2, + "contests": [ + [5, 1], + [4, 0], + [6, 1], + [2, 1], + [8, 0] + ], + "expected": 21 + } +] diff --git a/src/hackerrank/interview_preparation_kit/greedy_algorithms/minimum_absolute_difference_in_an_array.js b/src/hackerrank/interview_preparation_kit/greedy_algorithms/minimum_absolute_difference_in_an_array.js index fe7871f2..1665c4ce 100644 --- a/src/hackerrank/interview_preparation_kit/greedy_algorithms/minimum_absolute_difference_in_an_array.js +++ b/src/hackerrank/interview_preparation_kit/greedy_algorithms/minimum_absolute_difference_in_an_array.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/greedy_algorithms/minimum-absolute-difference-in-an-array.md]] */ -export function minimumAbsoluteDifference(arr) { +function minimumAbsoluteDifference(arr) { const sortedNums = arr.map((x) => x).sort((a, b) => b - a); let result = Math.abs(sortedNums[sortedNums.length - 1] - sortedNums[0]); @@ -20,3 +20,4 @@ export function minimumAbsoluteDifference(arr) { } export default { minimumAbsoluteDifference }; +export { minimumAbsoluteDifference }; diff --git a/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.js b/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.js index 6b3b7552..bc5d4fbc 100644 --- a/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.js +++ b/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.js @@ -5,7 +5,7 @@ const __BINARY_BASE__ = 2; const __NUMBER_SIZE_IN_BITS__ = 32; -export function flippingBits(n) { +function flippingBits(n) { let nBinaryStr = n.toString(__BINARY_BASE__); nBinaryStr = nBinaryStr.padStart(__NUMBER_SIZE_IN_BITS__, '0'); @@ -23,3 +23,4 @@ export function flippingBits(n) { } export default { flippingBits }; +export { flippingBits }; diff --git a/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.test.js b/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.test.js index 89519345..e7792b88 100644 --- a/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.test.js +++ b/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.test.js @@ -2,56 +2,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger.js'; import { flippingBits } from './flipping-bits.js'; - -const TEST_CASES = [ - { - title: 'Sample Test Case 0', - tests: [ - { - input: 2147483647, - expected: 2147483648 - }, - { - input: 1, - expected: 4294967294 - }, - { - input: 0, - expected: 4294967295 - } - ] - }, - { - title: 'Sample Test Case 1', - tests: [ - { - input: 4, - expected: 4294967291 - }, - { - input: 123456, - expected: 4294843839 - } - ] - }, - { - title: 'Sample Test Case 2', - tests: [ - { - input: 0, - expected: 4294967295 - }, - { - input: 802743475, - expected: 3492223820 - }, - { - input: 35601423, - expected: 4259365872 - } - ] - } -]; +import TEST_CASES from './flipping-bits.testcases.json'; describe('flipping bits', () => { it('flipping bits test cases', () => { diff --git a/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.testcases.json b/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.testcases.json new file mode 100644 index 00000000..86e90789 --- /dev/null +++ b/src/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.testcases.json @@ -0,0 +1,54 @@ +[ + { + "title": "Sample Test Case 0", + "tests": + [ + { + "input": 2147483647, + "expected": 2147483648 + }, + { + "input": 1, + "expected": 4294967294 + }, + { + "input": 0, + "expected": 4294967295 + } + ] + }, + { + "title": "Sample Test Case 1", + "tests": + [ + + { + "input": 4, + "expected": 4294967291 + }, + { + "input": 123456, + "expected": 4294843839 + } + ] + }, + { + "title": "Sample Test Case 2", + "tests": + [ + + { + "input": 0, + "expected": 4294967295 + }, + { + "input": 802743475, + "expected": 3492223820 + }, + { + "input": 35601423, + "expected": 4259365872 + } + ] + } +] diff --git a/src/hackerrank/interview_preparation_kit/miscellaneous/friend_circle_queries.js b/src/hackerrank/interview_preparation_kit/miscellaneous/friend_circle_queries.js index 4a16327d..921dd035 100644 --- a/src/hackerrank/interview_preparation_kit/miscellaneous/friend_circle_queries.js +++ b/src/hackerrank/interview_preparation_kit/miscellaneous/friend_circle_queries.js @@ -56,7 +56,7 @@ class GropingFriends { } } -export function maxCircle(queries) { +function maxCircle(queries) { const result = []; const friends = new GropingFriends(); @@ -72,3 +72,4 @@ export function maxCircle(queries) { } export default { maxCircle }; +export { maxCircle }; diff --git a/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_fibonacci_numbers.js b/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_fibonacci_numbers.js index 73f7a31b..2d331d76 100644 --- a/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_fibonacci_numbers.js +++ b/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_fibonacci_numbers.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_fibonacci_numbers.md]] */ -export function fibonacci(n) { +function fibonacci(n) { if (n === 0) { return 0; } @@ -14,3 +14,4 @@ export function fibonacci(n) { } export default { fibonacci }; +export { fibonacci }; diff --git a/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_recursive_staircase.js b/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_recursive_staircase.js index 4c7c7a32..0c635d14 100644 --- a/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_recursive_staircase.js +++ b/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/ctci_recursive_staircase.js @@ -6,7 +6,7 @@ const TOP_LIMIT = 10 ** 10 + 7; const STEPSLIMIT = 3; -export class StepPerms { +class StepPerms { TOP_LIMIT = 1; STEPS_LIMIT = 1; @@ -39,10 +39,11 @@ export class StepPerms { } } -export function stepPerms(n) { +function stepPerms(n) { const stairs = new StepPerms(TOP_LIMIT, STEPSLIMIT); return stairs.stepPermsComputWithCache(n) % TOP_LIMIT; } export default { stepPerms, StepPerms }; +export { stepPerms, StepPerms }; diff --git a/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/recursive_digit_sum.js b/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/recursive_digit_sum.js index ced86843..68e0cd16 100644 --- a/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/recursive_digit_sum.js +++ b/src/hackerrank/interview_preparation_kit/recursion_and_backtracking/recursive_digit_sum.js @@ -4,7 +4,7 @@ const RADIX = 10; -export function superDigitCompute(n) { +function superDigitCompute(n) { if (n.length === 1) { return parseInt(n, RADIX); } @@ -17,7 +17,7 @@ export function superDigitCompute(n) { return superDigitCompute(`${partial}`); } -export function superDigit(n, k) { +function superDigit(n, k) { const accumulator = `${superDigitCompute(n)}`; let result = ''; @@ -29,3 +29,4 @@ export function superDigit(n, k) { } export default { superDigit }; +export { superDigit }; diff --git a/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor.js b/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor.js index ce28178b..9c9603c8 100644 --- a/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor.js +++ b/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/search/ctci-ice-cream-parlor.md]] */ -export function whatFlavorsCompute(cost, money) { +function whatFlavorsCompute(cost, money) { const cache = {}; const RADIX = 10; @@ -20,8 +20,9 @@ export function whatFlavorsCompute(cost, money) { return []; } -export function whatFlavors(cost, money) { +function whatFlavors(cost, money) { console.log(whatFlavorsCompute(cost, money)?.join(' ')); } export default { whatFlavorsCompute, whatFlavors }; +export { whatFlavorsCompute, whatFlavors }; diff --git a/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor_bruteforce.js b/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor_bruteforce.js index 5eafcbb3..631c99be 100644 --- a/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor_bruteforce.js +++ b/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor_bruteforce.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/search/ctci-ice-cream-parlor.md]] */ -export function whatFlavorsBruteforceCompute(cost, money) { +function whatFlavorsBruteforceCompute(cost, money) { const RADIX = 10; for (const key of Object.keys(cost)) { @@ -22,8 +22,9 @@ export function whatFlavorsBruteforceCompute(cost, money) { return []; } -export function whatFlavors(cost, money) { +function whatFlavors(cost, money) { console.log(whatFlavorsBruteforceCompute(cost, money)?.join(' ')); } export default { whatFlavorsBruteforceCompute, whatFlavors }; +export { whatFlavorsBruteforceCompute, whatFlavors }; diff --git a/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor_optimized.js b/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor_optimized.js index 95a313dc..8378c84a 100644 --- a/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor_optimized.js +++ b/src/hackerrank/interview_preparation_kit/search/ctci_ice_cream_parlor_optimized.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/search/ctci-ice-cream-parlor.md]] */ -export function whatFlavorsCompute(cost, money) { +function whatFlavorsCompute(cost, money) { let ans1; let ans2; @@ -44,8 +44,9 @@ export function whatFlavorsCompute(cost, money) { return Array.from(result); } -export function whatFlavors(cost, money) { +function whatFlavors(cost, money) { console.log(whatFlavorsCompute(cost, money)?.join(' ')); } export default { whatFlavorsCompute, whatFlavors }; +export { whatFlavorsCompute, whatFlavors }; diff --git a/src/hackerrank/interview_preparation_kit/search/swap_nodes_algo.js b/src/hackerrank/interview_preparation_kit/search/swap_nodes_algo.js index c2d8ca51..386cf355 100644 --- a/src/hackerrank/interview_preparation_kit/search/swap_nodes_algo.js +++ b/src/hackerrank/interview_preparation_kit/search/swap_nodes_algo.js @@ -1,16 +1,16 @@ /** - * @link Problem export functioninition [[docs/hackerrank/interview_preparation_kit/search/swap-nodes-algo.md]] + * @link Problem definition [[docs/hackerrank/interview_preparation_kit/search/swap-nodes-algo.md]] */ import { Node } from '../../lib/Node.js'; // CONSTANTS -export const __INITIAL_LEVEL__ = 1; -export const __ROOT_VALUE__ = 1; -export const __LEAF_VALUE__ = -1; +const __INITIAL_LEVEL__ = 1; +const __ROOT_VALUE__ = 1; +const __LEAF_VALUE__ = -1; const __RADIX__ = 10; -export class Tree { +class Tree { root; nodeCollector; @@ -97,7 +97,7 @@ export class Tree { } } -export function swapNodes(indexes, queries) { +function swapNodes(indexes, queries) { const tree = new Tree(indexes); let nodeCollector = tree.getCollector(); const output = []; @@ -126,4 +126,5 @@ export function swapNodes(indexes, queries) { return output; } -export default { swapNodes, __INITIAL_LEVEL__ }; +export default { swapNodes, Tree, __INITIAL_LEVEL__ }; +export { swapNodes, Tree, __INITIAL_LEVEL__ }; diff --git a/src/hackerrank/interview_preparation_kit/sort/ctci_bubble_sort.js b/src/hackerrank/interview_preparation_kit/sort/ctci_bubble_sort.js index 757ab24d..b5c4af8c 100644 --- a/src/hackerrank/interview_preparation_kit/sort/ctci_bubble_sort.js +++ b/src/hackerrank/interview_preparation_kit/sort/ctci_bubble_sort.js @@ -4,7 +4,7 @@ const SEPARATOR = '\n'; -export class SortableGroup { +class SortableGroup { group; count; @@ -38,7 +38,7 @@ export class SortableGroup { } } -export function countSwaps(a) { +function countSwaps(a) { const sortableGroup = new SortableGroup(a); sortableGroup.bubble_sort(); @@ -53,3 +53,4 @@ export function countSwaps(a) { } export default { countSwaps, SortableGroup }; +export { countSwaps, SortableGroup }; diff --git a/src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.Player.js b/src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.Player.js index cfc6bef6..4476e7f7 100644 --- a/src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.Player.js +++ b/src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.Player.js @@ -1,6 +1,6 @@ // Start Given code -export class Player { +class Player { name = ''; score = 0; @@ -18,3 +18,4 @@ export class Player { // End Given code export default { Player }; +export { Player }; diff --git a/src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.js b/src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.js index 0ddfed6a..d0e903f7 100644 --- a/src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.js +++ b/src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.js @@ -4,7 +4,7 @@ import { Player } from './ctci_comparator_sorting.Player.js'; -export class SortablePlayer extends Player { +class SortablePlayer extends Player { name = ''; score = 0; @@ -34,14 +34,20 @@ export class SortablePlayer extends Player { } } -export function comparatorSorting(players) { +function comparatorSorting(players) { const sortedPlayers = [...players].sort((a, b) => a.comparator(b)); return sortedPlayers.map((player) => player.toString()); } -export function comparatorSortingPrint(players) { +function comparatorSortingPrint(players) { console.log(comparatorSorting(players)?.join('\n')); } -export default { Player, SortablePlayer, comparatorSorting }; +export default { + Player, + SortablePlayer, + comparatorSorting, + comparatorSortingPrint +}; +export { Player, SortablePlayer, comparatorSorting, comparatorSortingPrint }; diff --git a/src/hackerrank/interview_preparation_kit/sort/mark_and_toys.js b/src/hackerrank/interview_preparation_kit/sort/mark_and_toys.js index a33999ae..1b862b43 100644 --- a/src/hackerrank/interview_preparation_kit/sort/mark_and_toys.js +++ b/src/hackerrank/interview_preparation_kit/sort/mark_and_toys.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/sort/mark-and-toys.md]] */ -export function maximumToys(prices, k) { +function maximumToys(prices, k) { const group = [...prices]; group.sort((a, b) => a - b); @@ -21,3 +21,4 @@ export function maximumToys(prices, k) { } export default { maximumToys }; +export { maximumToys }; diff --git a/src/hackerrank/interview_preparation_kit/stacks_and_queues/balanced_brackets.js b/src/hackerrank/interview_preparation_kit/stacks_and_queues/balanced_brackets.js index 921b21c4..6f9bf529 100644 --- a/src/hackerrank/interview_preparation_kit/stacks_and_queues/balanced_brackets.js +++ b/src/hackerrank/interview_preparation_kit/stacks_and_queues/balanced_brackets.js @@ -5,7 +5,7 @@ const __YES__ = 'YES'; const __NO__ = 'NO'; -export function isBalancedCompute(s) { +function isBalancedCompute(s) { const pairs = { '{': '}', '(': ')', '[': ']' }; const brackets = []; @@ -27,8 +27,9 @@ export function isBalancedCompute(s) { return brackets.length <= 0; } -export function isBalanced(s) { +function isBalanced(s) { return isBalancedCompute(s) ? __YES__ : __NO__; } export default { isBalanced }; +export { isBalanced }; diff --git a/src/hackerrank/interview_preparation_kit/string_manipulation/alternating_characters.js b/src/hackerrank/interview_preparation_kit/string_manipulation/alternating_characters.js index 1645feef..1738ef8b 100644 --- a/src/hackerrank/interview_preparation_kit/string_manipulation/alternating_characters.js +++ b/src/hackerrank/interview_preparation_kit/string_manipulation/alternating_characters.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/string_manipulation/alternating-characters.md]] */ -export function alternatingCharacters(s) { +function alternatingCharacters(s) { let last = ''; let newString = ''; @@ -18,3 +18,4 @@ export function alternatingCharacters(s) { } export default { alternatingCharacters }; +export { alternatingCharacters }; diff --git a/src/hackerrank/interview_preparation_kit/string_manipulation/ctci_making_anagrams.js b/src/hackerrank/interview_preparation_kit/string_manipulation/ctci_making_anagrams.js index 60db8a61..9a76b3f7 100644 --- a/src/hackerrank/interview_preparation_kit/string_manipulation/ctci_making_anagrams.js +++ b/src/hackerrank/interview_preparation_kit/string_manipulation/ctci_making_anagrams.js @@ -19,7 +19,7 @@ function sum(values) { ); } -export function makeAnagram(a, b) { +function makeAnagram(a, b) { const aMap = charToDicMap(a); const bMap = charToDicMap(b); @@ -34,3 +34,4 @@ export function makeAnagram(a, b) { } export default { makeAnagram }; +export { makeAnagram }; diff --git a/src/hackerrank/interview_preparation_kit/string_manipulation/sherlock_and_valid_string.js b/src/hackerrank/interview_preparation_kit/string_manipulation/sherlock_and_valid_string.js index e2da4dc3..7e68561a 100644 --- a/src/hackerrank/interview_preparation_kit/string_manipulation/sherlock_and_valid_string.js +++ b/src/hackerrank/interview_preparation_kit/string_manipulation/sherlock_and_valid_string.js @@ -5,7 +5,7 @@ const __YES__ = 'YES'; const __NO__ = 'NO'; -export function isValidCompute(s) { +function isValidCompute(s) { if (s.length <= 1) { return true; } @@ -48,8 +48,9 @@ export function isValidCompute(s) { return false; } -export function isValid(s) { +function isValid(s) { return isValidCompute(s) ? __YES__ : __NO__; } export default { isValid }; +export { isValid }; diff --git a/src/hackerrank/lib/BigIntMath.js b/src/hackerrank/lib/BigIntMath.js index 2dc6966b..52e4f8eb 100644 --- a/src/hackerrank/lib/BigIntMath.js +++ b/src/hackerrank/lib/BigIntMath.js @@ -1,6 +1,6 @@ /* istanbul ignore file */ -export class BigIntMath { +class BigIntMath { static max(...values) { if (values.length === 0) { return null; @@ -79,3 +79,4 @@ export class BigIntMath { } export default { BigIntMath }; +export { BigIntMath }; diff --git a/src/hackerrank/lib/Node.js b/src/hackerrank/lib/Node.js index 45290a12..12db1ec1 100644 --- a/src/hackerrank/lib/Node.js +++ b/src/hackerrank/lib/Node.js @@ -1,6 +1,6 @@ /* istanbul ignore file */ -export class Node { +class Node { left; right; @@ -15,3 +15,4 @@ export class Node { } export default { Node }; +export { Node }; diff --git a/src/hackerrank/projecteuler/euler001.js b/src/hackerrank/projecteuler/euler001.js index 23ced128..f096a8d9 100644 --- a/src/hackerrank/projecteuler/euler001.js +++ b/src/hackerrank/projecteuler/euler001.js @@ -3,12 +3,12 @@ */ // Function to return gcd of a and b -export function gcd(a, b) { +function gcd(a, b) { if (a === 0) return b; return gcd(b % a, a); } -export function sumAp(n, d) { +function sumAp(n, d) { // Number of terms const _n = Math.floor(n / d); @@ -16,10 +16,13 @@ export function sumAp(n, d) { } // Function to find the sum of all multiples of a and b below n -export function euler001(a, b, n) { +function euler001(a, b, n) { // Since, we need the sum of multiples less than N const _n = n - 1; const lcm = Math.floor((a * b) / gcd(a, b)); return sumAp(_n, a) + sumAp(_n, b) - sumAp(_n, lcm); } + +export default { euler001 }; +export { euler001 }; diff --git a/src/hackerrank/projecteuler/euler002.js b/src/hackerrank/projecteuler/euler002.js index 316d0cf5..f1267823 100644 --- a/src/hackerrank/projecteuler/euler002.js +++ b/src/hackerrank/projecteuler/euler002.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/projecteuler/euler002.md]] */ -export function fiboEvenSum(n) { +function fiboEvenSum(n) { let fibo1 = 1n; let fibo2 = 1n; let total = 0n; @@ -20,8 +20,9 @@ export function fiboEvenSum(n) { return total; } -export function euler002(n) { +function euler002(n) { return fiboEvenSum(n); } export default { euler002 }; +export { euler002 }; diff --git a/src/hackerrank/projecteuler/euler003.js b/src/hackerrank/projecteuler/euler003.js index dd3ebf88..e390f2a9 100644 --- a/src/hackerrank/projecteuler/euler003.js +++ b/src/hackerrank/projecteuler/euler003.js @@ -4,7 +4,7 @@ import { BigIntMath } from '../lib/BigIntMath.js'; -export function primeFactor(n) { +function primeFactor(n) { if (n < 2) { throw new Error('n must be greater than 2'); } @@ -26,8 +26,9 @@ export function primeFactor(n) { return maxPrimeFactor; } -export function euler003(n) { +function euler003(n) { return primeFactor(BigInt(n)); } export default { euler003 }; +export { euler003 }; diff --git a/src/hackerrank/warmup/aVeryBigSum.js b/src/hackerrank/warmup/aVeryBigSum.js index 0f99ade6..6d84283e 100644 --- a/src/hackerrank/warmup/aVeryBigSum.js +++ b/src/hackerrank/warmup/aVeryBigSum.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/aVeryBigSum.md]] */ -export function aVeryBigSum(ar) { +function aVeryBigSum(ar) { let result = 0; for (const num of ar) { @@ -13,3 +13,4 @@ export function aVeryBigSum(ar) { } export default { aVeryBigSum }; +export { aVeryBigSum }; diff --git a/src/hackerrank/warmup/birthdayCakeCandles.js b/src/hackerrank/warmup/birthdayCakeCandles.js index dbbf503f..bb727de0 100644 --- a/src/hackerrank/warmup/birthdayCakeCandles.js +++ b/src/hackerrank/warmup/birthdayCakeCandles.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/birthdayCakeCandles.md]] */ -export function birthdayCakeCandles(ar) { +function birthdayCakeCandles(ar) { if (ar.length === 0) { throw new Error('Empty input'); } @@ -23,3 +23,4 @@ export function birthdayCakeCandles(ar) { } export default { birthdayCakeCandles }; +export { birthdayCakeCandles }; diff --git a/src/hackerrank/warmup/compareTriplets.js b/src/hackerrank/warmup/compareTriplets.js index 4241856c..9f905c44 100644 --- a/src/hackerrank/warmup/compareTriplets.js +++ b/src/hackerrank/warmup/compareTriplets.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/compareTriplets.md]] */ -export function compareTriplets(a, b) { +function compareTriplets(a, b) { const awards = [0, 0]; if (a.length !== b.length) { @@ -21,3 +21,4 @@ export function compareTriplets(a, b) { } export default { compareTriplets }; +export { compareTriplets }; diff --git a/src/hackerrank/warmup/diagonalDifference.js b/src/hackerrank/warmup/diagonalDifference.js index e48fa92a..56378528 100644 --- a/src/hackerrank/warmup/diagonalDifference.js +++ b/src/hackerrank/warmup/diagonalDifference.js @@ -4,7 +4,7 @@ import { logger as console } from '../../logger.js'; -export function diagonalDifference(arr) { +function diagonalDifference(arr) { let diag1 = 0; let diag2 = 0; const last = arr.length - 1; @@ -24,3 +24,4 @@ export function diagonalDifference(arr) { } export default { diagonalDifference }; +export { diagonalDifference }; diff --git a/src/hackerrank/warmup/miniMaxSum.js b/src/hackerrank/warmup/miniMaxSum.js index dc792bb4..000d00b7 100644 --- a/src/hackerrank/warmup/miniMaxSum.js +++ b/src/hackerrank/warmup/miniMaxSum.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/miniMaxSum.md]] */ -export function miniMaxSum(arr) { +function miniMaxSum(arr) { if (arr.length === 0) { throw new Error('Empty input'); } @@ -27,3 +27,4 @@ export function miniMaxSum(arr) { } export default { miniMaxSum }; +export { miniMaxSum }; diff --git a/src/hackerrank/warmup/plusMinus.js b/src/hackerrank/warmup/plusMinus.js index b67c7bb3..6a19869a 100644 --- a/src/hackerrank/warmup/plusMinus.js +++ b/src/hackerrank/warmup/plusMinus.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/plusMinus.md]] */ -export function plusMinus(arr) { +function plusMinus(arr) { let positives = 0; let negatives = 0; let zeros = 0; @@ -27,3 +27,4 @@ export function plusMinus(arr) { } export default { plusMinus }; +export { plusMinus }; diff --git a/src/hackerrank/warmup/simpleArraySum.js b/src/hackerrank/warmup/simpleArraySum.js index be7376f7..feec4e68 100644 --- a/src/hackerrank/warmup/simpleArraySum.js +++ b/src/hackerrank/warmup/simpleArraySum.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/simpleArraySum.md]] */ -export function simpleArraySum(ar) { +function simpleArraySum(ar) { let acum = 0; for (const num of ar) { @@ -13,3 +13,4 @@ export function simpleArraySum(ar) { } export default { simpleArraySum }; +export { simpleArraySum }; diff --git a/src/hackerrank/warmup/solveMeFirst.js b/src/hackerrank/warmup/solveMeFirst.js index 41ad7102..649f2921 100644 --- a/src/hackerrank/warmup/solveMeFirst.js +++ b/src/hackerrank/warmup/solveMeFirst.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/solveMeFirst.md]] */ -export function solveMeFirst(inputLines) { +function solveMeFirst(inputLines) { let result = 0; const radix = 10; @@ -14,3 +14,4 @@ export function solveMeFirst(inputLines) { } export default { solveMeFirst }; +export { solveMeFirst }; diff --git a/src/hackerrank/warmup/staircase.js b/src/hackerrank/warmup/staircase.js index 8b6b4ad0..707e00f9 100644 --- a/src/hackerrank/warmup/staircase.js +++ b/src/hackerrank/warmup/staircase.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/staircase.md]] */ -export function staircase(n) { +function staircase(n) { const result = []; for (let i = 1; i <= n; i++) { @@ -23,3 +23,4 @@ export function staircase(n) { } export default { staircase }; +export { staircase }; diff --git a/src/hackerrank/warmup/timeConversion.js b/src/hackerrank/warmup/timeConversion.js index 368bd56c..bf85e3cb 100644 --- a/src/hackerrank/warmup/timeConversion.js +++ b/src/hackerrank/warmup/timeConversion.js @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/warmup/timeConversion.md]] */ -export function timeConversion(s) { +function timeConversion(s) { let meridian = s.substring(s.length - 2, s.length); meridian = meridian.toLowerCase(); @@ -26,3 +26,4 @@ export function timeConversion(s) { } export default { timeConversion }; +export { timeConversion }; diff --git a/src/problem0000.js b/src/problem0000.js index 2dee8fe4..83a9502f 100644 --- a/src/problem0000.js +++ b/src/problem0000.js @@ -6,7 +6,7 @@ import { logger as console } from './logger.js'; -export function problem0000() { +function problem0000() { const result = null; console.log(`result ${String(result)}`); @@ -15,3 +15,4 @@ export function problem0000() { } export default { problem0000 }; +export { problem0000 }; diff --git a/src/projecteuler/problem0017.js b/src/projecteuler/problem0017.js index 7ed41d21..dd150124 100644 --- a/src/projecteuler/problem0017.js +++ b/src/projecteuler/problem0017.js @@ -5,7 +5,7 @@ import { logger as console } from '../logger.js'; import { numberToWord } from './helpers/index.js'; -export default function problem0017(init, last) { +function problem0017(init, last) { let replaced; let word; let acum = 0; @@ -24,4 +24,5 @@ export default function problem0017(init, last) { return acum; } +export default { problem0017 }; export { problem0017 }; diff --git a/src/projecteuler/problem0018.js b/src/projecteuler/problem0018.js index 15075b8e..bff25afc 100644 --- a/src/projecteuler/problem0018.js +++ b/src/projecteuler/problem0018.js @@ -7,7 +7,7 @@ import { logger as console } from '../logger.js'; const rootCoordinateI = 0; const rootCoordinateJ = 0; -export function problem0018(_triangle) { +function problem0018(_triangle) { console.debug('_triangle', _triangle); console.debug( '_triangle', @@ -33,3 +33,4 @@ export function problem0018(_triangle) { } export default { problem0018 }; +export { problem0018 }; diff --git a/src/projecteuler/problem0019.js b/src/projecteuler/problem0019.js index 277ec383..b5647ad2 100644 --- a/src/projecteuler/problem0019.js +++ b/src/projecteuler/problem0019.js @@ -6,7 +6,7 @@ import { daysInMonth, __SUNDAY__ } from '../constants/index.js'; const __FEBRUARY__KEY__ = 'FEBRUARY'; -export function problem0019( +function problem0019( _dayOfWeek = __SUNDAY__, _sinceYear = 1901, _untilYear = 2000 @@ -44,3 +44,4 @@ export function problem0019( } export default { problem0019 }; +export { problem0019 }; diff --git a/src/projecteuler/problem0020.js b/src/projecteuler/problem0020.js index a9c1baa1..b457e4a1 100644 --- a/src/projecteuler/problem0020.js +++ b/src/projecteuler/problem0020.js @@ -13,7 +13,7 @@ import { logger as console } from '../logger.js'; import { bigFactorial, bigSumMany } from './helpers/bigNumbers.js'; -export function problem0020(_limit) { +function problem0020(_limit) { const strFactorial = bigFactorial(_limit); console.log(`Factorial of ${_limit}!:`, strFactorial); @@ -24,3 +24,4 @@ export function problem0020(_limit) { } export default { problem0020 }; +export { problem0020 }; diff --git a/src/projecteuler/problem0021.js b/src/projecteuler/problem0021.js index 7feb12a2..c6309665 100644 --- a/src/projecteuler/problem0021.js +++ b/src/projecteuler/problem0021.js @@ -19,7 +19,7 @@ import { logger as console } from '../logger.js'; import { divisors, bigSumMany } from './helpers/index.js'; -export function problem0021(_start, _limit) { +function problem0021(_start, _limit) { const data = {}; for (let i = _start; i <= _limit; i++) { @@ -49,3 +49,4 @@ export function problem0021(_start, _limit) { } export default { problem0021 }; +export { problem0021 }; diff --git a/src/projecteuler/problem0022.js b/src/projecteuler/problem0022.js index 67cbfa4b..197c903c 100644 --- a/src/projecteuler/problem0022.js +++ b/src/projecteuler/problem0022.js @@ -5,7 +5,7 @@ import { logger as console } from '../logger.js'; import { wordScore } from './helpers/wordScore.js'; -export function problem0022(listOfNames) { +function problem0022(listOfNames) { listOfNames.sort((a, b) => a.localeCompare(b)); let result = 0; @@ -21,3 +21,4 @@ export function problem0022(listOfNames) { } export default { problem0022 }; +export { problem0022 }; diff --git a/src/projecteuler/problem0023.js b/src/projecteuler/problem0023.js index a34c67f7..82d543a3 100644 --- a/src/projecteuler/problem0023.js +++ b/src/projecteuler/problem0023.js @@ -5,7 +5,7 @@ import { logger as console } from '../logger.js'; import { abundance, ___DIVISORS_ABUNDANT___, sum } from './helpers/index.js'; -export function problem0023(_underLimit, _superLimit) { +function problem0023(_underLimit, _superLimit) { const allNumsList = []; const abundantNumberList = []; @@ -64,3 +64,4 @@ export function problem0023(_underLimit, _superLimit) { } export default { problem0023 }; +export { problem0023 }; diff --git a/src/projecteuler/problem0024.js b/src/projecteuler/problem0024.js index 6d5e45fd..c25821fb 100644 --- a/src/projecteuler/problem0024.js +++ b/src/projecteuler/problem0024.js @@ -34,7 +34,7 @@ const permute = (symbols, target) => { return answer; }; -export function problem0024(inputElements, inputPermutationToFind) { +function problem0024(inputElements, inputPermutationToFind) { const permutationFound = permute(inputElements, inputPermutationToFind); console.debug(`result ${String(permutationFound)}`); @@ -43,3 +43,4 @@ export function problem0024(inputElements, inputPermutationToFind) { } export default { problem0024 }; +export { problem0024 }; diff --git a/src/projecteuler/problem0025.js b/src/projecteuler/problem0025.js index feeefb4d..1abd6af6 100644 --- a/src/projecteuler/problem0025.js +++ b/src/projecteuler/problem0025.js @@ -5,7 +5,7 @@ import { logger as console } from '../logger.js'; import { bigNum, bigSum, bigNumToString } from './helpers/index.js'; -export function problem0025(_top) { +function problem0025(_top) { let last1 = bigNum('1'); let last2 = bigNum('1'); let counter = 2; @@ -26,3 +26,4 @@ export function problem0025(_top) { } export default { problem0025 }; +export { problem0025 };