Skip to content

Commit 530b779

Browse files
author
Gonzalo Diaz
committed
[BUGFIX] SonarQube: Use for…of instead of .forEach(…).
Use "for...of" loops instead of "forEach" method calls javascript:S7728
1 parent 054a39f commit 530b779

File tree

59 files changed

+169
-168
lines changed

Some content is hidden

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

59 files changed

+169
-168
lines changed

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/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
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ describe('ctci_array_left_rotation', () => {
99
it('rotLeft Test cases', () => {
1010
expect.assertions(9);
1111

12-
ROT_LEFT_TEST_CASES.forEach((test) => {
12+
for (const test of ROT_LEFT_TEST_CASES) {
1313
const answer = rotLeft(test.input, test.d_rotations);
1414

1515
console.debug(`rotLeft(${test.numbers}) solution found: ${answer}`);
1616

1717
expect(answer).toStrictEqual(test.expected);
18-
});
18+
}
1919

2020
expect(ROT_LEFT_TEST_CASES).toHaveLength(8);
2121
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ describe('minimum swaps 2', () => {
99
it('minimumSwaps', () => {
1010
expect.assertions(4);
1111

12-
TEST_CASES.forEach((test) => {
12+
for (const test of TEST_CASES) {
1313
const answer = minimumSwaps(test.input);
1414

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

1717
expect(answer).toStrictEqual(test.expected);
18-
});
18+
}
1919

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

0 commit comments

Comments
 (0)