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
5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ <h2 class="data-error__title">Не удалось загрузить данны
</section>
</template>

<script src="js/main.js"></script>

<script src="js/main.js" type="module"></script>
</body>

</html>
</html>
75 changes: 75 additions & 0 deletions js/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { getRandomArrayElement } from './util.js';

const NAMES = [
'Артём',
'Борис',
'Владимир',
'Григорий',
'Денис',
'Анастасия',
'Валерия',
'Елена',
'Ирина',
'Ксения'
];

const DESCRIPTIONS = [
'Впечатления, которые остаются навсегда.',
'Каждый кадр - часть летней истории.',
'Простые вещи - самые важные.',
'Отдых - это искусство жить.',
'Вдохновение в каждом дне.',
'Уют в простых вещах.',
'Счастье в мелочах вокруг.',
'Эмоции, которые остаются навсегда.',
'Вкус к жизни в каждом дне.',
'Любовь к жизни в деталях.'
];

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

const SIMILAR_ARRAY_COUNT = 25;
const id = 25;

Check failure on line 40 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

'id' is assigned a value but never used
const likes = {

Check failure on line 41 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

'likes' is assigned a value but never used
MIN: 15,
MAX: 200
};
const COMMENTS = 30;
const Avatar = {
MIN: 1,
MAX: 6
};
const CommetsId = {
MIN: 10000,
MAX: 1_000_000
};

const getComment = () => ({
id: getRandomInteger(CommetsId.MIN, CommetsId.MAX),

Check failure on line 56 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

'getRandomInteger' is not defined
name: getRandomArrayElement(NAMES),
message: getRandomArrayElement(MESSAGES),
avatar: `./img/avatar-${getRandomInteger(Avatar.MIN, Avatar.MAX)}.svg`

Check failure on line 59 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

'getRandomInteger' is not defined
});

const createArray = (i) => ({
description: getRandomArrayElement(DESCRIPTIONS),
id: i,
url: `./pictures/${i}.jpg`,
likes: getRandomInteger(Likes.MIN, Likes.MAX),

Check failure on line 66 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

'Likes' is not defined

Check failure on line 66 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

'Likes' is not defined

Check failure on line 66 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

'getRandomInteger' is not defined
comments: Array.from({ length: getRandomInteger(0, COMMENTS) }, getComment)

Check failure on line 67 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

'getRandomInteger' is not defined
});

const similarArray = () => Array.from({ length: SIMILAR_ARRAY_COUNT }, (_, i) => createArray(i + 1));

export { similarArray };



Check failure on line 75 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Too many blank lines at the end of file. Max of 2 allowed
85 changes: 5 additions & 80 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,7 @@
const NAMES = [
'Артём',
'Борис',
'Владимир',
'Григорий',
'Денис',
'Анастасия',
'Валерия',
'Елена',
'Ирина',
'Ксения'
];

const DESCRIPTIONS = [
'Впечатления, которые остаются навсегда.',
'Каждый кадр - часть летней истории.',
'Простые вещи - самые важные.',
'Отдых - это искусство жить.',
'Вдохновение в каждом дне.',
'Уют в простых вещах.',
'Счастье в мелочах вокруг.',
'Эмоции, которые остаются навсегда.',
'Вкус к жизни в каждом дне.',
'Любовь к жизни в деталях.'
];

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

const SIMILAR_ARRAY_COUNT = 25;
const id = 25;
const likes = {
MIN: 15,
MAX: 200
};
const COMMENTS = 30;
const Avatar = {
MIN: 1,
MAX: 6
};
const CommetsId = {
MIN: 10000,
MAX: 1_000_000
};

const getRandomInteger = (a, b) => {
const lower = Math.ceil(Math.min(a, b));
const upper = Math.floor(Math.max(a, b));
const result = Math.random() * (upper - lower + 1) + lower;
return Math.floor(result);
};

const getRandomArrayElement = (elements) =>
elements[getRandomInteger(0, elements.length - 1)];

const getComment = () => ({
id: getRandomInteger(CommetsId.MIN, CommetsId.MAX),
name: getRandomArrayElement(NAMES),
message: getRandomArrayElement(MESSAGES),
avatar: `./img/avatar-${getRandomInteger(Avatar.MIN, Avatar.MAX)}.svg`
});

const createArray = (i) => ({
description: getRandomArrayElement(DESCRIPTIONS),
id: i,
url: `./pictures/${i}.jpg`,
likes: getRandomInteger(Likes.MIN, Likes.MAX),
comments: Array.from({ length: getRandomInteger(0, COMMENTS) }, getComment)
});

const similarArray = Array.from({ length: SIMILAR_ARRAY_COUNT }, (_, i) => createArray(i + 1));

console.log(similarArray);
import './util.js';
import { similarArray } from './data.js';

console.log(
similarArray()
);

11 changes: 11 additions & 0 deletions js/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const getRandomInteger = (a, b) => {
const lower = Math.ceil(Math.min(a, b));
const upper = Math.floor(Math.max(a, b));
const result = Math.random() * (upper - lower + 1) + lower;
return Math.floor(result);
};

const getRandomArrayElement = (elements) =>
elements[getRandomInteger(0, elements.length - 1)];

export { getRandomArrayElement };
Loading