Skip to content

Instantly share code, notes, and snippets.

@kerus1024
Last active May 17, 2019 09:24
Show Gist options
  • Save kerus1024/8e34042fc3f3305f62e8134e0c2e0b35 to your computer and use it in GitHub Desktop.
Save kerus1024/8e34042fc3f3305f62e8134e0c2e0b35 to your computer and use it in GitHub Desktop.
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