-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Aleksandr-Anokhin/module4-task1
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const PHOTO_COUNT = 25; | ||
|
||
const MESSAGES = [ | ||
'Всё отлично!', | ||
'В целом всё неплохо. Но не всё.', | ||
'У моего кота получилась фотография лучше.', | ||
]; | ||
|
||
const DESCRIPTIONS = [ | ||
'Утро!', | ||
'Котик', | ||
'Солнышко', | ||
'Красивое фото', | ||
'Что-то новенькое', | ||
]; | ||
|
||
const NAMES = [ | ||
'Иван', | ||
'Себастьян', | ||
'Мария', | ||
'Кристоф', | ||
'Виктор', | ||
'Юлия', | ||
]; | ||
|
||
const getRandomIntInclusive = (min, max) => { | ||
min = Math.ceil(min); | ||
max = Math.floor(max); | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
}; | ||
|
||
const counter = () => { | ||
let sum = 0; | ||
return () => { | ||
sum = sum + 1; | ||
return sum; | ||
}; | ||
}; | ||
|
||
const uniquePhoto = counter(); | ||
const uniqueId = counter(); | ||
const getRandomArrayElement = (elements) => elements[getRandomIntInclusive(0, elements.length - 1)]; | ||
|
||
const createComments = () => ({ | ||
id: getRandomIntInclusive(0, 30), | ||
avatar: `img/avatar-${getRandomIntInclusive(1, 6)}.svg`, | ||
message: getRandomArrayElement(MESSAGES), | ||
name: getRandomArrayElement(NAMES), | ||
}); | ||
|
||
|
||
const createPhoto = () => { | ||
const id = uniqueId(); | ||
return { | ||
id: id, | ||
url: `photos/${uniquePhoto()}.jpg`, | ||
description: getRandomArrayElement(DESCRIPTIONS), | ||
likes: getRandomIntInclusive(15, 200), | ||
comments: Array.from({ length: getRandomIntInclusive(0, 30) }, createComments), | ||
}; | ||
}; | ||
|
||
const createPhotos = () => Array.from({ length: PHOTO_COUNT }, createPhoto); | ||
|
||
console.log( | ||
createPhotos() | ||
); |