Skip to content

Commit 6d74cf6

Browse files
author
Gonzalo Diaz
committed
[BUGFIX] SonarQube: Do not call Array#push() multiple times.
Multiple consecutive calls to methods that accept multiple arguments should be combined typescript:S7778
1 parent dc14a5e commit 6d74cf6

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
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/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/warmup/plusMinus.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function plusMinus(arr: number[]): string {
1717
}
1818
}
1919

20-
const result: string[] = [];
21-
22-
result.push((positives / arr.length).toFixed(6));
23-
result.push((negatives / arr.length).toFixed(6));
24-
result.push((zeros / arr.length).toFixed(6));
20+
const result: string[] = [
21+
(positives / arr.length).toFixed(6),
22+
(negatives / arr.length).toFixed(6),
23+
(zeros / arr.length).toFixed(6)
24+
];
2525

2626
return result.join(`\n`);
2727
}

0 commit comments

Comments
 (0)