Skip to content

Commit 8cfa546

Browse files
authored
Merge pull request #780 from sir-gon/develop
Develop
2 parents 9330333 + 5854c78 commit 8cfa546

File tree

69 files changed

+202
-190
lines changed

Some content is hidden

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

69 files changed

+202
-190
lines changed

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ DOCKER_COMPOSE=docker compose
3333
.PHONY: all clean dependencies help list test outdated
3434
.EXPORT_ALL_VARIABLES: # (2)
3535

36+
define crono
37+
@start=$$(date +%s); \
38+
$(1); \
39+
end=$$(date +%s); \
40+
diff=$$((end - start)); \
41+
printf "Total time: %02d:%02d:%02d\n" $$((diff/3600)) $$((diff%3600/60)) $$((diff%60))
42+
endef
43+
44+
3645
help: list
3746

3847
list:
@@ -135,7 +144,8 @@ compose/test: compose/build
135144
compose/run: compose/build
136145
${DOCKER_COMPOSE} --profile production run --rm algorithm-exercises-js make run
137146

138-
all: env dependencies test
147+
all:
148+
$(call crono, make clean && make dependencies && make build && make test && make lint && make coverage/html)
139149

140150
run:
141151
ls -alh

src/hackerrank/implementation/countingValleys.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function countingValleys(steps, path) {
1111

1212
console.debug(stepList);
1313

14-
stepList.forEach((step) => {
14+
for (const step of stepList) {
1515
if (step === 'D') {
1616
if (altitude === 0) {
1717
valleys += 1;
@@ -21,7 +21,7 @@ function countingValleys(steps, path) {
2121
if (step === 'U') {
2222
altitude += 1;
2323
}
24-
});
24+
}
2525

2626
return valleys;
2727
}

src/hackerrank/implementation/migratoryBirds.js

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

5-
import util from 'util';
5+
import util from 'node:util';
66
import { logger as console } from '../../logger.js';
77

88
function migratoryBirds(arr) {
@@ -16,10 +16,10 @@ function migratoryBirds(arr) {
1616
for (const bird of arr) {
1717
console.debug(`bird ${bird}`);
1818

19-
if (!map[bird]) {
20-
map[bird] = 1;
21-
} else {
19+
if (map[bird]) {
2220
map[bird] += 1;
21+
} else {
22+
map[bird] = 1;
2323
}
2424

2525
console.debug(`bird = ${bird} ~> map[bird] = ${map[bird]}`);

src/hackerrank/implementation/repeatedString.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ function countAs(word) {
99

1010
const chars = word.split('');
1111

12-
chars.forEach((char) => {
12+
for (const char of chars) {
1313
if (char === 'a') {
1414
result += 1;
1515
}
16-
});
16+
}
1717

1818
return result;
1919
}

src/hackerrank/implementation/sockMerchant.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ function sockMerchant(n, ar) {
99

1010
const matches = {};
1111

12-
ar.forEach((v) => {
12+
for (const v of ar) {
1313
matches[v] = matches?.[v] ? matches[v] + 1 : 1;
14-
});
14+
}
1515

1616
console.debug(matches);
1717

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ describe('arrays: 2d Array hourglassSum', () => {
88
it('hourglassSum Test Cases', () => {
99
expect.assertions(4);
1010

11-
TEST_CASES.forEach((test) => {
11+
for (const test of TEST_CASES) {
1212
const answer = hourglassSum(test.input);
1313

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

1818
expect(answer).toStrictEqual(test.expected);
19-
});
19+
}
2020

2121
expect(TEST_CASES).toHaveLength(3);
2222
});

src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ function arrayManipulation(n, queries) {
1111
const result = Array(LENGTH).fill(SURROGATE_VALUE);
1212
let maximum = 0;
1313

14-
queries.forEach((query) => {
14+
for (const query of queries) {
1515
const [aStart, bEnd, kValue] = query;
1616
console.debug(`start -> ${result}`);
1717

1818
for (let i = aStart; i <= bEnd; i++) {
1919
result[i] += kValue;
2020
console.debug(`result -> ${result}`);
2121
}
22-
});
22+
}
2323

24-
result.forEach((value) => {
24+
for (const value of result) {
2525
maximum = Math.max(value, maximum);
26-
});
26+
}
2727

2828
return maximum;
2929
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ describe('arrays: crush (bruteforce) small cases', () => {
99
it('arrayManipulation Test Cases', () => {
1010
expect.assertions(4);
1111

12-
TEST_CASES.forEach((test) => {
12+
for (const test of TEST_CASES) {
1313
const answer = arrayManipulation(test.n, test.queries);
1414

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

1919
expect(answer).toStrictEqual(test.expected);
20-
});
20+
}
2121

2222
expect(TEST_CASES).toHaveLength(3);
2323
});

src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ function arrayManipulation(n, queries) {
1111
const result = Array(LENGTH).fill(INITIAL_VALUE);
1212
let maximum = 0;
1313

14-
queries.forEach((query) => {
14+
for (const query of queries) {
1515
const [aStart, bEnd, kValue] = query;
1616

1717
result[aStart] += kValue;
1818
result[bEnd + 1] -= kValue;
19-
});
19+
}
2020

2121
let accumSum = 0;
2222

23-
result.forEach((value) => {
23+
for (const value of result) {
2424
accumSum += value;
2525
maximum = Math.max(maximum, accumSum);
26-
});
26+
}
2727

2828
return maximum;
2929
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ describe('arrays: crush (optimized)', () => {
99
it('arrayManipulation Test Cases', () => {
1010
expect.assertions(4);
1111

12-
TEST_CASES.forEach((test) => {
12+
for (const test of TEST_CASES) {
1313
const answer = arrayManipulation(test.n, test.queries);
1414

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

1919
expect(answer).toStrictEqual(test.expected);
20-
});
20+
}
2121

2222
expect(TEST_CASES).toHaveLength(3);
2323
});

0 commit comments

Comments
 (0)