-
Notifications
You must be signed in to change notification settings - Fork 1
Модуляция #4
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
Merged
keksobot
merged 5 commits into
htmlacademy-javascript:master
from
Vitali3207:module5-task1
Mar 12, 2026
Merged
Модуляция #4
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,30 +1,49 @@ | ||
| // Функция для проверки длины строки. | ||
|
|
||
| const checkStringLength = (string, maxLength) => string.length <= maxLength; | ||
| // const checkStringLength = (string, maxLength) => string.length <= maxLength; | ||
|
|
||
| checkStringLength(); | ||
| // checkStringLength(); | ||
|
|
||
| // Функция для проверки, является ли строка палиндромом. | ||
|
|
||
| const isPalindrom = (string) => { | ||
| const optimizedString = string.replaceAll(' ', '').toLowerCase(); | ||
| let newString = ''; | ||
| // const isPalindrom = (string) => { | ||
| // const optimizedString = string.replaceAll(' ', '').toLowerCase(); | ||
| // let newString = ''; | ||
|
|
||
| for (let i = optimizedString.length - 1; i >= 0; i--) { | ||
| newString += optimizedString[i]; | ||
| } | ||
| // for (let i = optimizedString.length - 1; i >= 0; i--) { | ||
| // newString += optimizedString[i]; | ||
| // } | ||
|
|
||
| return newString === optimizedString; | ||
| }; | ||
| // return newString === optimizedString; | ||
| // }; | ||
|
|
||
| isPalindrom(); | ||
| // isPalindrom(); | ||
|
|
||
|
|
||
| const getNumber = (string) => { | ||
| const numberString = string.toString().replace(/\D/g, ''); | ||
| // const getNumber = (string) => { | ||
| // const numberString = string.toString().replace(/\D/g, ''); | ||
|
|
||
| return parseInt(numberString, 10); | ||
| }; | ||
| // return parseInt(numberString, 10); | ||
| // }; | ||
|
|
||
| // getNumber(); | ||
|
|
||
|
|
||
| // Функция из Доп.задания пятого раздела ДЗ. | ||
|
|
||
| getNumber(); | ||
| const timeWorking = (timeStart, timeStop, timeMeet, duration) => { | ||
| let start = timeStart.split(':'); | ||
| start = (parseInt(start[0], 10) * 60) + parseInt(start[1], 10); | ||
|
|
||
| let end = timeStop.split(':'); | ||
| end = (parseInt(end[0], 10) * 60) + parseInt(end[1], 10); | ||
|
|
||
| let meet = timeMeet.split(':'); | ||
| meet = (parseInt(meet[0], 10) * 60) + parseInt(meet[1], 10); | ||
|
|
||
| return !!(start <= meet + duration && meet + duration <= end); | ||
|
|
||
| }; | ||
| console.log(timeWorking('8:00', '17:30', '14:00', 211)); | ||
|
|
||
| // Алексей подскажи как тут лучше всего сделать рефакторинг? | ||
This file contains hidden or 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,65 @@ | ||
| import { getRandomInteger, getRandomArrayElement } from './util.js'; | ||
|
|
||
| const NAMES = [ | ||
| 'Владимир', | ||
| 'Генадий', | ||
| 'Олег', | ||
| 'Виталий', | ||
| 'Максим', | ||
| 'Наталья', | ||
| 'Светлана', | ||
| 'Ольга', | ||
| 'Ева' | ||
| ]; | ||
|
|
||
| const DESCRIPTIONS = [ | ||
| 'Замечательное фото', | ||
| 'Отличный ракурс', | ||
| 'Классная идея', | ||
| 'Красивое фото', | ||
| 'Это фото заслуживае отдельного внимания', | ||
| 'Можно сразу на обложку журнала', | ||
| 'У тебя определённо талант!!!' | ||
| ]; | ||
|
|
||
| const MESSAGES = [ | ||
| 'Всё отлично!', | ||
| 'В целом всё неплохо.', | ||
| 'Но не всё.', | ||
| 'Когда вы делаете фотографию, хорошо бы убирать палец из кадра.', | ||
| 'В конце концов это просто непрофессионально.', | ||
| 'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.', | ||
| 'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.', | ||
| 'Лица у людей на фотке перекошены, как будто их избивают., Как можно было поймать такой неудачный момент?!' | ||
| ]; | ||
|
|
||
| const PHOTO_COUNT = 25; | ||
|
|
||
| const createIdGenirator = () => { | ||
| let currentId = 0; | ||
|
|
||
| return () => ++currentId; | ||
| }; | ||
|
|
||
| const generatePhotoId = createIdGenirator(); | ||
| const generateCommentsId = createIdGenirator(); | ||
| const generateUrl = createIdGenirator(); | ||
|
|
||
| const createComentsPhoto = () => ({ | ||
| id: generateCommentsId(), | ||
| avatar: `img/avatar-${getRandomInteger(1, 6)}.svg`, | ||
| message: getRandomArrayElement(MESSAGES), | ||
| name: getRandomArrayElement(NAMES) | ||
| }); | ||
|
|
||
| const createPhoto = () => ({ | ||
| id: generatePhotoId(1, 25), | ||
| url: `photos/${generateUrl(1, 25)}.jpg`, | ||
| description: getRandomArrayElement(DESCRIPTIONS), | ||
| likes: getRandomInteger(15, 200), | ||
| comments: Array.from({ length: getRandomInteger(0, 30) }, createComentsPhoto) | ||
| }); | ||
|
|
||
| const generatePhotos = () => Array.from({ length: PHOTO_COUNT }, createPhoto); | ||
|
|
||
| export { generatePhotos }; |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,71 +1,4 @@ | ||
| const NAMES = [ | ||
| 'Владимир', | ||
| 'Генадий', | ||
| 'Олег', | ||
| 'Виталий', | ||
| 'Максим', | ||
| 'Наталья', | ||
| 'Светлана', | ||
| 'Ольга', | ||
| 'Ева' | ||
| ]; | ||
|
|
||
| const DESCRIPTION = [ | ||
| 'Замечательное фото', | ||
| 'Отличный ракурс', | ||
| 'Классная идея', | ||
| 'Красивое фото', | ||
| 'Это фото заслуживае отдельного внимания', | ||
| 'Можно сразу на обложку журнала', | ||
| 'У тебя определённо талант!!!' | ||
| ]; | ||
|
|
||
| const MESSAGES = [ | ||
| 'Всё отлично!', | ||
| 'В целом всё неплохо.', | ||
| 'Но не всё.', | ||
| 'Когда вы делаете фотографию, хорошо бы убирать палец из кадра.', | ||
| 'В конце концов это просто непрофессионально.', | ||
| 'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.', | ||
| 'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.', | ||
| 'Лица у людей на фотке перекошены, как будто их избивают., Как можно было поймать такой неудачный момент?!']; | ||
|
|
||
|
|
||
| const getRandomInteger = (min, max) => { | ||
| min = Math.ceil(min); | ||
| max = Math.floor(max); | ||
|
|
||
| return Math.floor(Math.random() * (max - min + 1) + min); | ||
| }; | ||
|
|
||
| const getRandomArrayElement = (elements) => elements[getRandomInteger(0, elements.length - 1)]; | ||
|
|
||
| const createIdGenirator = () => { | ||
| let currentId = 0; | ||
|
|
||
| return () => ++currentId; | ||
| }; | ||
|
|
||
| const generatePhotoId = createIdGenirator(); | ||
| const generateCommentsId = createIdGenirator(); | ||
| const generateUrl = createIdGenirator(); | ||
|
|
||
| const PHOTO_COUNT = 25; | ||
|
|
||
| const createComentsPhoto = () => ({ | ||
| id: generateCommentsId(), | ||
| avatar: `img/avatar-${getRandomInteger(1, 6)}.svg`, | ||
| message: getRandomArrayElement(MESSAGES), | ||
| name: getRandomArrayElement(NAMES) | ||
| }); | ||
|
|
||
| const createFotoDescription = () => ({ | ||
| id: generatePhotoId(1, 25), | ||
| url: `photos/${generateUrl(1, 25)}.jpg`, | ||
| description: getRandomArrayElement(DESCRIPTION), | ||
| likes: getRandomInteger(15, 200), | ||
| comments: Array.from({ length: getRandomInteger(0, 30) }, createComentsPhoto) | ||
| }); | ||
|
|
||
| const photoObject = Array.from({ length: PHOTO_COUNT }, createFotoDescription); | ||
| import { generatePhotos } from './generator.js'; | ||
| import './util.js'; | ||
|
|
||
| console.log(generatePhotos()); | ||
This file contains hidden or 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,10 @@ | ||
| const getRandomInteger = (min, max) => { | ||
| min = Math.ceil(min); | ||
| max = Math.floor(max); | ||
|
|
||
| return Math.floor(Math.random() * (max - min + 1) + min); | ||
| }; | ||
|
|
||
| const getRandomArrayElement = (elements) => elements[getRandomInteger(0, elements.length - 1)]; | ||
|
|
||
| export { getRandomInteger, getRandomArrayElement }; |
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.
Отдельно util.js не надо подключать его по цепочке подключит твой модуль генерации данных