-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Больше деталей #4
Merged
craz3r
merged 2 commits into
htmlacademy-javascript:master
from
Daniil888-m:module4-task1
Nov 26, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,96 @@ | ||
const NAMES = [ | ||
'Кристина', | ||
'Игорь', | ||
'Зина', | ||
'Петруша', | ||
'Макс', | ||
'Кирилл', | ||
'Алекс', | ||
'Коля', | ||
'Ксения', | ||
'Алина' | ||
]; | ||
const DESCRIPTIONS = [ | ||
'Солнечный берег с белым песком и пальмами.', | ||
'Ночной город с огнями и движением автомобилей.', | ||
'Улыбающиеся дети, играющие в парке.', | ||
'Закат над горами с яркими оранжевыми и красными оттенками.', | ||
'Стейк на гриле с овощами на стороне.', | ||
'Старый замок на вершине холма, окруженный туманом.', | ||
'Лесная тропинка среди осенних деревьев с разноцветной листвой.', | ||
'Пара, прогуливающаяся по мосту, держа друг друга за руки.', | ||
'Домашний офис с приятной атмосферой и растениями.', | ||
'Уютный кафе с чашкой кофе и книгой на столе.', | ||
'Дети, строящие снеговика на зимнем дворе.', | ||
'Спокойное озеро с отражением облаков на воде.', | ||
'Уличный рынок с яркими фруктами и овощами.', | ||
'Групповой снимок друзей на пляже.', | ||
'Кошка, спящая на окне в солнечный день.' | ||
]; | ||
const MESSAGES = [ | ||
'Всё отлично!', | ||
'В целом всё неплохо.Но не всё.', | ||
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра.В конце концов это просто непрофессионально.', | ||
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.', | ||
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.', | ||
'Лица у людей на фотке перекошены, как будто их избивают.Как можно было поймать такой неудачный момент ? !' | ||
]; | ||
function getRandomInt(min, max) { | ||
min = Math.ceil(min); | ||
max = Math.floor(max); | ||
const randomInt = Math.floor(Math.random() * (max - min + 1)) + min; | ||
return randomInt; | ||
} | ||
function getUniqueId(min, max) { | ||
const receivedId = []; | ||
|
||
return function () { | ||
if (receivedId.length >= (max - min + 1)) { | ||
return receivedId[receivedId.length - 1]; | ||
} | ||
let currentId = getRandomInt(min, max); | ||
while (receivedId.includes(currentId)) { | ||
currentId = getRandomInt(min, max); | ||
} | ||
receivedId.push(currentId); | ||
return currentId; | ||
}; | ||
} | ||
function getRandomElement(elements) { | ||
return elements[getRandomInt(0, elements.length - 1)]; | ||
} | ||
const getPhotoId = getUniqueId(1, 25); | ||
const getCommentId = getUniqueId(1, 1000); | ||
function createPhoto() { | ||
|
||
const photoId = getPhotoId(); | ||
const comments = []; | ||
|
||
for (let j = 0; j < getRandomInt(0, 30); j++) { | ||
const commentId = getCommentId(); | ||
const comment = { | ||
id: commentId, | ||
avatar: `img/avatar-${getRandomInt(1, 6)}.svg`, | ||
message: getRandomElement(MESSAGES), | ||
name: getRandomElement(NAMES), | ||
}; | ||
comments.push(comment); | ||
} | ||
const photo = { | ||
id: photoId, | ||
url: `photos/${photoId}.jpg`, | ||
description: getRandomElement(DESCRIPTIONS), | ||
likes: getRandomInt(15, 200), | ||
comments: comments | ||
}; | ||
|
||
return photo; | ||
} | ||
|
||
function getPhotos() { | ||
const photos = Array.from({ length: 25 }, createPhoto); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вынести 25 в константу |
||
return photos; | ||
} | ||
|
||
getPhotos(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments: comments => comments