Skip to content
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

Функции возвращаются #5

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions js/create-photo.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,53 @@
import { getPhotoData } from './data.js';
import { getPhotoSettings } from './photo-settings.js';
import { getRandomUniqueNumbers, getRandomArrayElement, getRandomNumber } from './utils.js';

const PhotosQuantity = {
MIN: 1,
MAX: 25,
};

const AvatarsQuantity = {
MIN: 1,
MAX: 6,
};

const LikesQuantity = {
MIN: 15,
MAX: 200,
};

const CommentsIdQuantity = {
MIN: 1,
MAX: 1000,
};

const CommentsForPhotoQuantity = {
MIN: 0,
MAX: 30,
};

const MessagesForCommentQuantity = {
MIN: 1,
MAX: 2,
};

const createPhoto = () => {

const generateCommentIds = getRandomUniqueNumbers(getPhotoSettings().CommentsIdQuantity.MIN, getPhotoSettings().CommentsIdQuantity.MAX);
const generagePtohoIds = getRandomUniqueNumbers(getPhotoSettings().PhotosQuantity.MIN, getPhotoSettings().PhotosQuantity.MAX);
const generatePhotoUrls = getRandomUniqueNumbers(getPhotoSettings().PhotosQuantity.MIN, getPhotoSettings().PhotosQuantity.MAX);
const generateCommentIds = getRandomUniqueNumbers(CommentsIdQuantity.MIN, CommentsIdQuantity.MAX);
const generagePtohoIds = getRandomUniqueNumbers(PhotosQuantity.MIN, PhotosQuantity.MAX);
const generatePhotoUrls = getRandomUniqueNumbers(PhotosQuantity.MIN, PhotosQuantity.MAX);

const getCommentMessages = (messages) => {
const array = [];
for (let i = 1; i <= getRandomNumber(getPhotoSettings().MessagesForCommentQuantity.MIN, getPhotoSettings().MessagesForCommentQuantity.MAX); i++) {
for (let i = 1; i <= getRandomNumber(MessagesForCommentQuantity.MIN, MessagesForCommentQuantity.MAX); i++) {
array.push(getRandomArrayElement(messages));
}
return array;
};

const createComment = () => ({
id: generateCommentIds(),
avatar: `img/avatar-${getRandomNumber(getPhotoSettings().AvatarsQuantity.MIN, getPhotoSettings().AvatarsQuantity.MAX)}.svg`,
avatar: `img/avatar-${getRandomNumber(AvatarsQuantity.MIN, AvatarsQuantity.MAX)}.svg`,
message: getCommentMessages(getPhotoData().MESSAGES).join(' '),
name: getRandomArrayElement(getPhotoData().NAMES),
});
Expand All @@ -27,11 +56,9 @@ const createPhoto = () => {
id: generagePtohoIds(),
url: `photos/${generatePhotoUrls()}.jpg`,
description: getPhotoData().DESCRIPTIONS[getRandomNumber(0, getPhotoData().DESCRIPTIONS.length - 1)],
likes: getRandomNumber(getPhotoSettings().LikesQuantity.MIN, getPhotoSettings().LikesQuantity.MAX),
comments: Array.from({length: getRandomNumber(getPhotoSettings().CommentsForPhotoQuantity.MIN, getPhotoSettings().CommentsForPhotoQuantity.MAX)}, createComment),
likes: getRandomNumber(LikesQuantity.MIN, LikesQuantity.MAX),
comments: Array.from({length: getRandomNumber(CommentsForPhotoQuantity.MIN, CommentsForPhotoQuantity.MAX)}, createComment),
};
};

export { createPhoto };


export { createPhoto, PhotosQuantity };
2 changes: 1 addition & 1 deletion js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ const getPhotoData = () => {
];

return { DESCRIPTIONS, NAMES, MESSAGES };
}
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Убери функцию getPhotoData и экспортируй сразу export { DESCRIPTIONS, NAMES, MESSAGES }. Функция здесь абсолютно лишняя

export { getPhotoData };
23 changes: 22 additions & 1 deletion js/functions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Функция для проверки, является ли строка длиннее заданного числа

const isStringLonger = (string = '', maxLength = 1) => string.length <= maxLength;

Check failure on line 3 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

'isStringLonger' is assigned a value but never used


// Функция для проверки, является ли строка палиндромом

const isPalindrom = (string = '') => {

Check failure on line 7 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

'isPalindrom' is assigned a value but never used
string = string.toLowerCase().replaceAll(' ', '');
let reverseString = '';
for (let i = 0; i < string.length; i++) {
Expand All @@ -16,7 +15,7 @@

// Функция для извлечения числа из строки

const extractNumber = (string) => {

Check failure on line 18 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

'extractNumber' is assigned a value but never used
string = string.toString();
let number = '';
for (let i = 0; i < string.length; i++) {
Expand All @@ -26,3 +25,25 @@
}
return parseInt(number, 10);
};

// Функция, опеределяющая, выходит вреча за рамки рабочего времени или нет

const isDelayAtWork = (starWorkDayTime, endWorkDayTime, startMeetingTime, meetingTimeInMinute) => {

Check failure on line 31 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

'isDelayAtWork' is assigned a value but never used
const toNumber = (string) => {
const number = string.split(':');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Деструктуризируй массив const [hours, minutes] = string.split(':');

number[1] /= 60;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не ошибка, но рекомендация. Лучше приводить к минутам, чтоб не работать с числами с плавающей точкой

И здесь можно избежать присваивания, а сразу все делать в return, даже не сохраняя в result

const result = Number(number[0]) + number[1];
return result;
};

const startDay = toNumber(starWorkDayTime);
const endDay = toNumber(endWorkDayTime);
const startMeeting = toNumber(startMeetingTime);
const meetingTimeInHour = meetingTimeInMinute / 60;

if (startDay > startMeeting || endDay <= startMeeting || meetingTimeInHour > (endDay - startMeeting)) {
return false;
}

return true;
};
5 changes: 2 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getPhotoSettings } from './photo-settings.js';
import { createPhoto } from './create-photo.js';
import { createPhoto, PhotosQuantity } from './create-photo.js';

const photos = Array.from({length: getPhotoSettings().PhotosQuantity.MAX}, createPhoto);
const photos = Array.from({length: PhotosQuantity.MAX}, createPhoto);

Check failure on line 3 in js/main.js

View workflow job for this annotation

GitHub Actions / Check

'photos' is assigned a value but never used
42 changes: 0 additions & 42 deletions js/photo-settings.js

This file was deleted.

Loading