Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/src/math.js
1126 views
1
let modes = {
2
noob: [-3, 3,-3, 3, '+-', 15000, 10],
3
easy: [-10, 10, -10, 10, '*/+-', 20000, 40],
4
medium: [-40, 40, -20, 20, '*/+-', 40000, 150],
5
hard: [-100, 100, -70, 70, '*/+-', 60000, 350],
6
extreme: [-999999, 999999, -999999, 999999, '*/', 99999, 9999],
7
impossible: [-99999999999, 99999999999, -99999999999, 999999999999, '*/', 30000, 35000],
8
impossible2: [-999999999999999, 999999999999999, -999, 999, '/', 30000, 50000]
9
}
10
11
let operators = {
12
'+': '+',
13
'-': '-',
14
'*': '×',
15
'/': '÷'
16
}
17
18
function randomInt(from, to) {
19
if (from > to) [from, to] = [to, from]
20
from = Math.floor(from)
21
to = Math.floor(to)
22
return Math.floor((to - from) * Math.random() + from)
23
}
24
25
function pickRandom(list) {
26
return list[Math.floor(Math.random() * list.length)]
27
}
28
29
function genMath(mode) {
30
return new Promise((resolve, reject) => {
31
let [a1, a2, b1, b2, ops, time, bonus] = modes[mode]
32
let a = randomInt(a1, a2)
33
let b = randomInt(b1, b2)
34
let op = pickRandom([...ops])
35
let result = (new Function(`return ${a} ${op.replace('/', '*')} ${b < 0 ? `(${b})` : b}`))()
36
if (op == '/') [a, result] = [result, a]
37
hasil = {
38
soal: `${a} ${operators[op]} ${b}`,
39
mode: mode,
40
waktu: time,
41
hadiah: bonus,
42
jawaban: result
43
}
44
resolve(hasil)
45
})
46
}
47
48
module.exports = { modes, operators, randomInt, pickRandom, genMath }
49
50