mirror of
https://github.com/tiennm99/loto.git
synced 2026-10-13 18:15:53 +00:00
Create loto.js
This commit is contained in:
1 parent
43cc9881bf
commit
3101e08ea0
1 file changed
+23
@@ -0,0 +1,23 @@
|
||||
function randomNumbers(num, from, to) {
|
||||
let arr = Array.from({
|
||||
length: to - from
|
||||
}, (_, i) => from + i);
|
||||
arr.sort(() => 0.5 - Math.random());
|
||||
return arr.slice(0, num);
|
||||
}
|
||||
|
||||
let arr = randomNumbers(90, 1, 91);
|
||||
let i = 0;
|
||||
|
||||
const readline = require('readline');
|
||||
readline.emitKeypressEvents(process.stdin);
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.on('keypress', (str, key) => {
|
||||
if (key.ctrl && key.name === 'c') {
|
||||
console.log(JSON.stringify);
|
||||
process.exit();
|
||||
} else {
|
||||
console.log(`Next number: ${arr[i++]}\n`);
|
||||
}
|
||||
});
|
||||
console.log('Press any key...');
|
||||
Reference in new issue
Block a user