Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/functions.js"></script>
<script src="js/main.js"></script>
</body>
</html>
50 changes: 43 additions & 7 deletions js/functions.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,59 @@
function checkStringLength(string, maxLength) {
let stringLength = string.length;
let check = stringLength <= maxLength;
const stringLength = string.length;
const check = stringLength <= maxLength;
return check;
}

const checkString = (string, maxLength) => string.length <= maxLength;

Check failure on line 8 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

'checkString' is assigned a value but never used
console.log(checkStringLength('проверяемая строка', 8));
console.log(checkStringLength('проверяемая строка', 30));

Check failure on line 10 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(checkStringLength('проверяемая строка', 15));

Check failure on line 11 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement

Check failure on line 12 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
function checkPalindrome (string) {
let neutralString = string
.toLowerCase()
.replaceAll(' ', '');
function checkPalindrome(string) {
const neutralString = string
.toLowerCase()
.replaceAll(' ', '');
let reversedString = '';
for (let i = neutralString.length - 1; i >= 0; i--) {
reversedString += neutralString[i];
}
return neutralString == reversedString;
return neutralString === reversedString;
}

const isPalindrome = (text) => {
const normalized = text.toUpperCase().replaceAll(' ', '');

Check failure on line 25 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

'isPalindrome' is assigned a value but never used
let reversed = '';
for (let i = normalized.length - 1; i <= 0; i = i - 1) {
reversed += normalized[i];
}
return normalized === reversed;
};

const isPalindromeByArray = (line) => {
const normalized = line.toLowerCase().replaceAll(' ', '')

Check failure on line 34 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

'isPalindromeByArray' is assigned a value but never used
const reversed = normalized.split('').reverse().join('');

Check failure on line 35 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
return normalized === reversed;
}

Check failure on line 38 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
console.log(checkPalindrome('Довод'));
console.log(checkPalindrome('А роза упала на лапу Азора'));

Check failure on line 40 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(checkPalindrome('Гроза'));

Check failure on line 41 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement

const getNumbers = (text) => {
let allNumbers = '';

for (let j = 0; j < text.length; j++) {
const current = parseInt(text[j], 10);
if (!isNaN(current)) {
allNumbers += current;
}
}
return parseInt(allNumbers);
};

console.log(getNumbers('2023 год')); // 2023
console.log(getNumbers('ECMAScript 2022')); // 2022
console.log(getNumbers('1 кефир, 0.5 батона')); // 105
console.log(getNumbers('агент 007')); // 7
console.log(getNumbers('а я томат')); // NaN
75 changes: 75 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

const PHOTOS_COUNT = 25;
const Likes = {
MIN: 15,
MAX: 200
};
const CommentsCount = {
MIN: 0,
MAX: 30
};
const Names = [
'Мария',
'Юля',
'Павел',
'Антон',
'Катя',
'Даша'
];

const Descriptions = [
'Вид на горы',
'Горный пейзаж',
'Прогулка по лесу',
'Вид на озеро',
'Закат',
'Вечерняя прогулка'
];

const Comments = [
'Всё отлично!',
'В целом всё неплохо. Но не всё.',
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра. В конце концов это просто непрофессионально.',
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.',
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!'
];

export const getRandomNumber = (min, max) => {
const left = Math.ceil(Math.min(min, max));
const right = Math.floor(Math.max(min,max));
const random = Math.random() * (right - left + 1) + left;
return Math.floor(random);
};

const getRandomElement = (elements) => elements[getRandomNumber(0, elements.length - 1)];

let commentId = 1;

const createComment = () => ({
id: commentId++,
avatar: `img/avatar-${getRandomNumber(1, 6)}.svg`,
message: getRandomElement(Comments),
name: getRandomElement(Names),
});

const getComments = () => {
const count = getRandomNumber(CommentsCount.MIN, CommentsCount.MAX);
const comments = [];
for (let i = 1; i <= count; i++) {
comments.push(createComment())
}
return comments;
};

const getPhoto = (k) => ({
id: k,
url: `photos/${k}.jpg`,
description: getRandomElement(Descriptions),
likes: getRandomNumber(Likes.MIN, Likes.MAX),
comments: getComments()
});

const getPhotos = (count) => Array.from({ length: count }, (_, i) => getPhoto(i + 1));

console.log(getPhotos(PHOTOS_COUNT));
Loading