Last active
May 17, 2019 09:24
-
-
Save kerus1024/8e34042fc3f3305f62e8134e0c2e0b35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lottery = () => { | |
const numArray = []; | |
const startNumber = 1; | |
const endNumber = 45; | |
const numCount = 6; | |
if (startNumber > endNumber) | |
return console.error('Error!'); | |
if (endNumber - startNumber < numCount) | |
return console.error('Error!'); | |
for (let i = 0; i < numCount; i++) { | |
while(true) { | |
const catchNumber = Math.floor(Math.random() * endNumber) + startNumber; | |
if (numArray.indexOf(catchNumber) === -1) { | |
numArray.push(catchNumber); | |
break; | |
} | |
} | |
} | |
numArray.sort((a, b) => { | |
return a - b; | |
}); | |
console.log(numArray); | |
} | |
for (let i = 0; i < 5; i++) lottery(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment