Skip to content

Commit

Permalink
Merge pull request #10 from Daniil888-m/module5-task2
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Dec 3, 2024
2 parents a9093d7 + e67aa09 commit 957edb4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 27 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h2 class="success__title">Изображение успешно загруже
<h2 class="data-error__title">Не удалось загрузить данные</h2>
</section>
</template>
<script src="js/main.js"></script>
<script src="js/main.js" type="module"></script>
<script src="js/functions.js"></script>
</body>

Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function checkStr(string, length) {
return string.length <= length;
}
checkStr('fff', 3);

function isPalindrome(string) {
string = string.toLowerCase().replaceAll(' ', '');
const reversedString = string.split('').reverse().join('');
return string === reversedString;
}
isPalindrome('ooppoo ooppoo');
function getNums(string) {
string = String(string);
let result = '';
for (let i = 0; i < string.length; i++) {
if (!isNaN(parseInt(string[i], 10))) {
result += string[i];
}
}
return parseInt(result, 10);
}

getNums('ou8kj9');

function getTimeInMinutes(time) {
const [hours, minutes] = time.split(':').map((elem) => parseInt(elem, 10));
return hours * 60 + minutes;
}

function checkMeetingTime(from, until, meetTime, duration) {
from = getTimeInMinutes(from);
until = getTimeInMinutes(until);
meetTime = getTimeInMinutes(meetTime);

return from <= meetTime && meetTime + duration <= until;
}
checkMeetingTime('08:00', '14:30', '14:00', 30);
24 changes: 0 additions & 24 deletions js/get-comments.js

This file was deleted.

23 changes: 21 additions & 2 deletions js/get-photos.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import { getComments } from './get-comments.js';
import { DESCRIPTIONS, PHOTOS_COUNT } from './data.js';
import { DESCRIPTIONS, PHOTOS_COUNT, NAMES, MESSAGES } from './consts.js';
import { getRandomInt, getUniqueId, getRandomElement } from './utils.js';


const getCommentId = getUniqueId(1, 1000);

function createComment() {
const commentId = getCommentId();
const comment = {
id: commentId,
avatar: `img/avatar-${getRandomInt(1, 6)}.svg`,
message: getRandomElement(MESSAGES),
name: getRandomElement(NAMES),
};

return comment;
}

function getComments() {
const comments = Array.from({ length: getRandomInt(0, 30) }, createComment);
return comments;
}

const getPhotoId = getUniqueId(1, 25);
function createPhoto() {
const photoId = getPhotoId();
Expand Down
1 change: 1 addition & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getPhotos } from './get-photos.js';

getPhotos();

0 comments on commit 957edb4

Please sign in to comment.