From 55c317fa41105e44b81446b44e6bc4d101189577 Mon Sep 17 00:00:00 2001 From: Ayronhayd <128861928+Ayronhayd@users.noreply.github.com> Date: Sun, 3 Mar 2024 18:12:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=80=D0=B3=D0=B0=D0=BD=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=B4=D0=B0=20+=20?= =?UTF-8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20'?= =?UTF-8?q?=D0=94=D0=B5=D0=BB=D1=83=20=E2=80=94=20=D0=B2=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D1=8F'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 1 + js/check-string-length.js | 4 -- js/extract-number.js | 16 ------- js/functions.js | 48 ++++++++++++++++++++ js/main.js | 15 +----- js/test-polyndrome.js | 13 ------ js/{ => utils}/create-random-Id-generator.js | 0 js/{ => utils}/generated-object.js | 40 +++++++++------- js/{ => utils}/get-random-integer.js | 0 js/{ => utils}/make-counter.js | 0 10 files changed, 73 insertions(+), 64 deletions(-) delete mode 100644 js/check-string-length.js delete mode 100644 js/extract-number.js create mode 100644 js/functions.js delete mode 100644 js/test-polyndrome.js rename js/{ => utils}/create-random-Id-generator.js (100%) rename js/{ => utils}/generated-object.js (78%) rename js/{ => utils}/get-random-integer.js (100%) rename js/{ => utils}/make-counter.js (100%) diff --git a/index.html b/index.html index 3aee8cc..09d5e84 100644 --- a/index.html +++ b/index.html @@ -234,5 +234,6 @@

Не удалось загрузить данны + diff --git a/js/check-string-length.js b/js/check-string-length.js deleted file mode 100644 index 893552d..0000000 --- a/js/check-string-length.js +++ /dev/null @@ -1,4 +0,0 @@ -const checkStringLength = (string = '', maxSymbols = 1) => string.length <= maxSymbols; -export { - checkStringLength -}; diff --git a/js/extract-number.js b/js/extract-number.js deleted file mode 100644 index 779b795..0000000 --- a/js/extract-number.js +++ /dev/null @@ -1,16 +0,0 @@ -const extractNumber = (string) => { - let result = ''; - - string = string.toString(); - - for (let i = 0; i <= string.length; i++) { - if (Number.isNaN(parseInt(string[i], 10)) === false) { - result += string[i]; - } - } - return result === '' ? NaN : Number(result); -}; - -export { - extractNumber -}; diff --git a/js/functions.js b/js/functions.js new file mode 100644 index 0000000..0170a26 --- /dev/null +++ b/js/functions.js @@ -0,0 +1,48 @@ +const checkStringLength = (string = '', maxSymbols = 1) => string.length <= maxSymbols; +checkStringLength('проверяемая строка', 20); + +const testPolyndrome = (string = '') => { + string = string.replaceAll(' ', '').toLowerCase(); + let reversal = ''; + + for (let i = string.length - 1; i >= 0; i--) { + reversal += string[1]; + } + return string === reversal; +}; +testPolyndrome('Лёша на полке клопа нашёл '); + +const extractNumber = (string) => { + let result = ''; + + string = string.toString(); + + for (let i = 0; i <= string.length; i++) { + if (Number.isNaN(parseInt(string[i], 10)) === false) { + result += string[i]; + } + } + return result === '' ? NaN : Number(result); +}; +extractNumber('извлекает содержащиеся в ней цифры от 0 до 9'); + +const checkMeetingTime = (startDayTime, endDayTime, startmeetingTime, duration) => { + + function countMinutes(time) { + const [hours, minutes] = time.split(':'); + return hours * 60 + parseInt(minutes, 10); + } + + const startDayminutes = countMinutes(startDayTime); + const endDayMinutes = countMinutes(endDayTime); + const startMeetingminutes = countMinutes(startmeetingTime); + const endMeetingMinutes = startMeetingminutes + duration; + + return startDayminutes <= startMeetingminutes && endMeetingMinutes <= endDayMinutes; +}; + +checkMeetingTime('08:00', '17:30', '14:00', 90); +checkMeetingTime('8:0', '10:0', '8:0', 120); +checkMeetingTime('08:00', '14:30', '14:00', 90); +checkMeetingTime('14:00', '17:30', '08:0', 90); +checkMeetingTime('8:00', '17:30', '08:00', 900); diff --git a/js/main.js b/js/main.js index a952d20..7e617e7 100644 --- a/js/main.js +++ b/js/main.js @@ -1,18 +1,5 @@ import { generatedObjectArrays -} from './generated-object'; -import { - checkStringLength -} from './check-string-length'; -import { - extractNumber -} from './extract-number'; -import { - testPolyndrome -} from './test-polyndrome'; - +} from './utils/generated-object'; -checkStringLength('проверяемая строка', 20); -extractNumber('извлекает содержащиеся в ней цифры от 0 до 9'); -testPolyndrome('Лёша на полке клопа нашёл '); generatedObjectArrays(); diff --git a/js/test-polyndrome.js b/js/test-polyndrome.js deleted file mode 100644 index ba0e6f8..0000000 --- a/js/test-polyndrome.js +++ /dev/null @@ -1,13 +0,0 @@ -const testPolyndrome = (string = '') => { - string = string.replaceAll(' ', '').toLowerCase(); - let reversal = ''; - - for (let i = string.length - 1; i >= 0; i--) { - reversal += string[1]; - } - return string === reversal; -}; - -export { - testPolyndrome -}; diff --git a/js/create-random-Id-generator.js b/js/utils/create-random-Id-generator.js similarity index 100% rename from js/create-random-Id-generator.js rename to js/utils/create-random-Id-generator.js diff --git a/js/generated-object.js b/js/utils/generated-object.js similarity index 78% rename from js/generated-object.js rename to js/utils/generated-object.js index 949c8ff..d3476a4 100644 --- a/js/generated-object.js +++ b/js/utils/generated-object.js @@ -8,21 +8,27 @@ import { makeCounter } from './make-counter.js'; -const Id = makeCounter(); -const Photoid = makeCounter(); +const createId = makeCounter(); +const createPhotoid = makeCounter(); const OBJECT_COUNT = 25; -const fixedValuesFromTo = { - MIN_COMMENTID: 1, - MAX_COMMENTID: 9999, - MIN_AVATAR: 1, - MAX_AVATAR: 6, - MIN_LIKES: 15, - MAX_LIKES: 200, - MIN_COMMENTS: 0, - MAX_COMMENTS: 30 +const COMMENTS_ID = { + min: 1, + max: 9999, +}; +const AVATARS = { + min: 1, + max: 6, +}; +const LIKES = { + min: 15, + max: 200, +}; +const COMMENTS = { + min: 0, + max: 30, }; -const generateCommentId = createRandomIdFromRangeGenerator(fixedValuesFromTo.MIN_COMMENTID, fixedValuesFromTo.MAX_COMMENTID); +const generateCommentId = createRandomIdFromRangeGenerator(COMMENTS_ID.min, COMMENTS_ID.max); const NAMES = [ @@ -72,18 +78,18 @@ const DESCRIPTIONS = [ const commentInformation = () => ({ id: generateCommentId(), - url: `img/avatar-${getRandomInteger(fixedValuesFromTo.MIN_AVATAR, fixedValuesFromTo.MAX_AVATAR)}.svg`, + url: `img/avatar-${getRandomInteger(AVATARS.min, AVATARS.max)}.svg`, message: MESSAGES[getRandomInteger(0, MESSAGES.length - 1)], name: `${NAMES[getRandomInteger(0, NAMES.length - 1)] } ${ SURNAMES[getRandomInteger(0, SURNAMES.length - 1)]}` }); const photoDescription = () => ({ - id: Id(), - url: `photos/${Photoid()}.jpg`, + id: createId(), + url: `photos/${createPhotoid()}.jpg`, description: DESCRIPTIONS[getRandomInteger(0, DESCRIPTIONS.length - 1)], - likes: getRandomInteger(fixedValuesFromTo.MIN_LIKES, fixedValuesFromTo.MAX_LIKES), + likes: getRandomInteger(LIKES.min, LIKES.min), comments: Array.from({ - length: getRandomInteger(fixedValuesFromTo.MIN_COMMENTS, fixedValuesFromTo.MAX_COMMENTS) + length: getRandomInteger(COMMENTS.min, COMMENTS.max) }, commentInformation) }); diff --git a/js/get-random-integer.js b/js/utils/get-random-integer.js similarity index 100% rename from js/get-random-integer.js rename to js/utils/get-random-integer.js diff --git a/js/make-counter.js b/js/utils/make-counter.js similarity index 100% rename from js/make-counter.js rename to js/utils/make-counter.js