Skip to content

Commit adba055

Browse files
committed
Работа над заданием 4.16
1 parent d2c3e0c commit adba055

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

js/main.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,23 @@ const MESSAGES = [
3232
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
3333
'Лица у людей на фотке перекошены, как будто их избивают.',
3434
'Как можно было поймать такой неудачный момент ?!'
35-
]
35+
];
3636

3737
const SIMILAR_ARRAY_COUNT = 25;
3838
const id = 25;
39-
const likes = 200;
40-
const comments = 30;
41-
const avatar = 25;
39+
const likes = {
40+
MIN: 15,
41+
MAX: 200
42+
};
43+
const COMMENTS = 30;
44+
const Avatar = {
45+
MIN: 1,
46+
MAX: 6
47+
};
48+
const CommetsId = {
49+
MIN: 10000,
50+
MAX: 1_000_000
51+
};
4252

4353
const getRandomInteger = (a, b) => {
4454
const lower = Math.ceil(Math.min(a, b));
@@ -50,18 +60,22 @@ const getRandomInteger = (a, b) => {
5060
const getRandomArrayElement = (elements) =>
5161
elements[getRandomInteger(0, elements.length - 1)];
5262

53-
const createArray = () => ({
63+
const getComment = () => ({
64+
id: getRandomInteger(CommetsId.MIN, CommetsId.MAX),
5465
name: getRandomArrayElement(NAMES),
5566
message: getRandomArrayElement(MESSAGES),
67+
avatar: `./img/avatar-${getRandomInteger(Avatar.MIN, Avatar.MAX)}.svg`
68+
});
69+
70+
const createArray = (i) => ({
5671
description: getRandomArrayElement(DESCRIPTIONS),
57-
id: getRandomArrayElement(id),
58-
url: getRandomArrayElement(url),
59-
likes: getRandomArrayElement(likes),
60-
comments: getRandomArrayElement(comments),
61-
avatar: photos / avatar - { getRandomArrayElement }.jpg
72+
id: i,
73+
url: `./pictures/${i}.jpg`,
74+
likes: getRandomInteger(Likes.MIN, Likes.MAX),
75+
comments: Array.from({ length: getRandomInteger(0, COMMENTS) }, getComment)
6276
});
6377

64-
const similarArray = Array.from({ length: SIMILAR_ARRAY_COUNT }, createArray);
78+
const similarArray = Array.from({ length: SIMILAR_ARRAY_COUNT }, (_, i) => createArray(i + 1));
6579

6680
console.log(similarArray);
6781

0 commit comments

Comments
 (0)