Skip to content

Commit

Permalink
Merge pull request #5 from Ayronhayd/module5-task2
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Mar 3, 2024
2 parents db46e98 + 55c317f commit 6fe5cf2
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 64 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,6 @@ <h2 class="data-error__title">Не удалось загрузить данны
</section>
</template>
<script src="js/main.js" type="module"></script>
<script src="js/functions.js"></script>
</body>
</html>
4 changes: 0 additions & 4 deletions js/check-string-length.js

This file was deleted.

16 changes: 0 additions & 16 deletions js/extract-number.js

This file was deleted.

48 changes: 48 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
@@ -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);
15 changes: 1 addition & 14 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -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();
13 changes: 0 additions & 13 deletions js/test-polyndrome.js

This file was deleted.

File renamed without changes.
40 changes: 23 additions & 17 deletions js/generated-object.js → js/utils/generated-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)
});

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 6fe5cf2

Please sign in to comment.