From 3e79a4b096170edc9fbe56c405c7de652e93e184 Mon Sep 17 00:00:00 2001 From: MaxSchmide Date: Sun, 6 Aug 2023 22:06:46 +0300 Subject: [PATCH] fix generator --- src/app.js | 1 - src/generator.js | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index 5d34de5..c54759b 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,3 @@ -/* eslint-disable space-before-function-paren */ /* eslint-disable no-console */ 'use strict'; diff --git a/src/generator.js b/src/generator.js index 45ba016..ac2ea11 100644 --- a/src/generator.js +++ b/src/generator.js @@ -1,7 +1,19 @@ 'use strict'; const generateRandomNumber = () => { - return Math.ceil(Math.random() * 10000); + const uniqueDigits = []; + + while (uniqueDigits.length < 4) { + const digit = Math.floor(Math.random() * 10); + + if (!uniqueDigits.includes(digit)) { + uniqueDigits.push(digit); + } + } + + const resultNumber = uniqueDigits.join(''); + + return parseInt(resultNumber); }; module.exports = { generateRandomNumber };