Skip to content

4.16. Больше деталей#3

Open
Alexlmth wants to merge 1 commit into
htmlacademy-javascript:masterfrom
Alexlmth:module4-task1
Open

4.16. Больше деталей#3
Alexlmth wants to merge 1 commit into
htmlacademy-javascript:masterfrom
Alexlmth:module4-task1

Conversation

@Alexlmth
Copy link
Copy Markdown
Contributor

@Alexlmth Alexlmth commented May 2, 2026

No description provided.

Comment thread js/main.js

const names = ['Николай', 'Дмитрий', 'Василий', 'Харитон', 'Алексей', 'София'];

const getRandomPositiveInteger = (a, b) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно сократить до getRandomInteger, а то со словом Positive название получается слишком длинное

Comment thread js/main.js
return Math.floor(result);
};

const getRandomArrayElement = (array) =>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо Element можно Item, так как слово Element обычно зарезервировано для DOM-элементов

Comment thread js/main.js
};

const getRandomArrayElement = (array) =>
array[getRandomPositiveInteger(0, array.length - 1)];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Последний элемент массива еще можно получить вот так array.at(-1)

Comment thread js/main.js

const createMessage = () => {
const arr = [];
for (let i = 1; i <= getRandomPositiveInteger(1, 2); i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Цикл for лучше заменить на for of

Comment thread js/main.js
};

const createComment = (index) => ({
id: index,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо index можно crypto.randomUUID()

Comment thread js/main.js

const createArrayComments = () => {
const arr = [];
for (let i = 1; i <= getRandomPositiveInteger(0, 30); i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как и выше лучше заменить на for ... of

Comment thread js/main.js
};

const createPictureItem = (index) => ({
id: index,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как и выше можно заменить на crypto.randomUUID()

Comment thread js/main.js
comments: createArrayComments()
});

const createArrayPictures = () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Создание массива можно заменить на реализацию Фабричного метода (это паттерн проектирования такой) для массиво в js

Array.from({length: 25}, createPictureItem);

Comment thread js/main.js

const createArrayPictures = () => {
const arr = [];
for (let i = 1; i <= 25; i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

25 - магическое число. Нужно завести под него константу

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants