Created
April 11, 2019 04:30
-
-
Save jcar787/ca062b3d2b33519cd295c64e90afcdc8 to your computer and use it in GitHub Desktop.
Exercise 4
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
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