Skip to content

Commit

Permalink
makeCounter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayronhayd committed Feb 28, 2024
1 parent d1ddad5 commit b2fb7f9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const OBJECT_COUNT = 25;
const fixedValuesFromTo = {
MIN_PHOTOID: 1,
MAX_PHOTOID: 25,
MIN_ID: 1,
MAX_ID: 25,
MIN_COMMENTID: 1,
MAX_COMMENTID: 9999,
MIN_AVATAR: 1,
Expand Down Expand Up @@ -59,6 +55,17 @@ const DESCRIPTIONS = [
'Любовь переносит все'
];

const makeCounter = () => {
let currentCount = 1;

return function() {
return currentCount++;
};
};

const Id = makeCounter();
const Photoid = makeCounter();

const getRandomInteger = (min, max) => {
const lower = Math.ceil(Math.min(Math.abs(min), Math.abs(max)));
const upper = Math.floor(Math.max(Math.abs(min), Math.abs(max)));
Expand All @@ -83,8 +90,6 @@ const createRandomIdFromRangeGenerator = (min, max) => {
};
};

const GeneratePhotoId = createRandomIdFromRangeGenerator(fixedValuesFromTo.MIN_PHOTOID, fixedValuesFromTo.MAX_PHOTOID);
const GenerateId = createRandomIdFromRangeGenerator(fixedValuesFromTo.MIN_ID, fixedValuesFromTo.MAX_ID);
const GenerateCommentId = createRandomIdFromRangeGenerator(fixedValuesFromTo.MIN_COMMENTID, fixedValuesFromTo.MAX_COMMENTID);

const commentInformation = () => ({
Expand All @@ -95,8 +100,8 @@ const commentInformation = () => ({
});

const photoDescription = () => ({
id: GenerateId(),
url: `photos/${GeneratePhotoId()}.jpg`,
id: Id(),
url: `photos/${Photoid()}.jpg`,
description: DESCRIPTIONS[getRandomInteger(0, DESCRIPTIONS.length - 1)],
likes: getRandomInteger(fixedValuesFromTo.MIN_LIKES, fixedValuesFromTo.MAX_LIKES),
comments: Array.from({
Expand All @@ -109,4 +114,5 @@ const generatedObjectArrays = () => Array.from({
length: OBJECT_COUNT
}, photoDescription);


generatedObjectArrays();

0 comments on commit b2fb7f9

Please sign in to comment.