Skip to content

Instantly share code, notes, and snippets.

@jcar787
Created April 11, 2019 04:30
Show Gist options
  • Save jcar787/ca062b3d2b33519cd295c64e90afcdc8 to your computer and use it in GitHub Desktop.
Save jcar787/ca062b3d2b33519cd295c64e90afcdc8 to your computer and use it in GitHub Desktop.
Exercise 4
function lotteryNum() {
return (Math.round(Math.random() * 100) % 58) + 1;
}
function pickNumber(numbers) {
let newNumber;
let found;
do {
newNumber = lotteryNum();
found = numbers.find(number => newNumber === number);
} while (found);
return [...numbers, newNumber].sort((a, b) => a - b);
}
var luckyLotteryNumbers = [];
for (var i = 0; i < 6; i++) {
luckyLotteryNumbers = pickNumber(Object.freeze(luckyLotteryNumbers));
}
console.log(luckyLotteryNumbers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment