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