Skip to content

Commit 2af34a4

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 javascript:S7778
1 parent b9802ee commit 2af34a4

File tree

1 file changed

+12
-13
lines changed
  • src/hackerrank/interview_preparation_kit/arrays

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
*/
44

55
function gethourGlass(arr, positionX, positionY) {
6-
const result = [];
7-
8-
// top
9-
result.push(arr[positionX - 1][positionY - 1]);
10-
result.push(arr[positionX - 1][positionY]);
11-
result.push(arr[positionX - 1][positionY + 1]);
12-
// middle
13-
result.push(arr[positionX][positionY]);
14-
// bottom
15-
result.push(arr[positionX + 1][positionY - 1]);
16-
result.push(arr[positionX + 1][positionY]);
17-
result.push(arr[positionX + 1][positionY + 1]);
18-
return result;
6+
return [
7+
// top
8+
arr[positionX - 1][positionY - 1],
9+
arr[positionX - 1][positionY],
10+
arr[positionX - 1][positionY + 1],
11+
// middle
12+
arr[positionX][positionY],
13+
// bottom
14+
arr[positionX + 1][positionY - 1],
15+
arr[positionX + 1][positionY],
16+
arr[positionX + 1][positionY + 1]
17+
];
1918
}
2019

2120
function hourglassSum(arr) {

0 commit comments

Comments
 (0)