Skip to content

Commit 9252454

Browse files
committed
Рефакторинг РУ
Убраны алиасы – кажется, они не нужны для таких простых типов, убраны избыточные аннотации типов. Для создания поля также как и для создания строки использован `Array.fill()`, а не цикл. Даже если оставить как было – `row` достаточно создать один раз вне цикла.
1 parent 1f2aaa8 commit 9252454

File tree

1 file changed

+3
-12
lines changed
  • modules/22-arrays/25-multi-dimensional-arrays

1 file changed

+3
-12
lines changed

modules/22-arrays/25-multi-dimensional-arrays/index.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
// BEGIN
2-
type Cell = null;
3-
type FieldRow = Cell[];
4-
type Field = FieldRow[];
5-
6-
function getField(size: number): Field {
7-
const field: Field = [];
8-
for (let i = 0; i < size; i += 1) {
9-
const row: FieldRow = Array<Cell>(size).fill(null, 0);
10-
field.push(row);
11-
}
12-
13-
return field;
2+
function getField(size: number): null[][] {
3+
const row = Array(size).fill(null);
4+
return Array(size).fill(row);
145
}
156
// END
167

0 commit comments

Comments
 (0)