Skip to content

Commit 3099958

Browse files
authored
Merge pull request #836 from sir-gon/develop
[BUGFIX] SonarQube: Prefer `Number.parseInt` over `parseInt`.
2 parents 910cd5b + 6d74cf6 commit 3099958

File tree

63 files changed

+191
-188
lines changed

Some content is hidden

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

63 files changed

+191
-188
lines changed

src/hackerrank/implementation/countApplesAndOranges.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ function countApplesAndOranges(
2525
}
2626
}
2727

28-
const result: number[] = [];
29-
result.push(cApples);
30-
result.push(cOranges);
28+
const result: number[] = [cApples, cOranges];
3129

3230
return result.join('\n');
3331
}

src/hackerrank/implementation/countingValleys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function countingValleys(steps: number, path: string): number {
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: number, path: string): number {
2121
if (step === 'U') {
2222
altitude += 1;
2323
}
24-
});
24+
}
2525

2626
return valleys;
2727
}

src/hackerrank/implementation/repeatedString.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ function countAs(word: string): number {
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.ts

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

1212
const matches: Matches = {};
1313

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

1818
console.debug(matches);
1919

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

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/2d_array.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ function gethourGlass(
77
positionX: number,
88
positionY: number
99
): number[] {
10-
const result: number[] = [];
10+
const result: number[] = [
11+
// top
12+
arr[positionX - 1][positionY - 1],
13+
arr[positionX - 1][positionY],
14+
arr[positionX - 1][positionY + 1],
15+
// middle
16+
arr[positionX][positionY],
17+
// bottom
18+
arr[positionX + 1][positionY - 1],
19+
arr[positionX + 1][positionY],
20+
arr[positionX + 1][positionY + 1]
21+
];
1122

12-
// top
13-
result.push(arr[positionX - 1][positionY - 1]);
14-
result.push(arr[positionX - 1][positionY]);
15-
result.push(arr[positionX - 1][positionY + 1]);
16-
// middle
17-
result.push(arr[positionX][positionY]);
18-
// bottom
19-
result.push(arr[positionX + 1][positionY - 1]);
20-
result.push(arr[positionX + 1][positionY]);
21-
result.push(arr[positionX + 1][positionY + 1]);
2223
return result;
2324
}
2425

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

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.toString()}) 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_bruteforce.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ function arrayManipulation(n: number, queries: number[][]): number {
1111
const result: number[] = new Array<number>(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.toString()}`);
1717

1818
for (let i = aStart; i <= bEnd; i++) {
1919
result[i] += kValue;
2020
console.debug(`result -> ${result.toString()}`);
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_optimized.test.ts

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.toString()}) 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.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ function arrayManipulation(n: number, queries: number[][]): number {
1111
const result = new 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
}

0 commit comments

Comments
 (0)