Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jajbshjahavahh
GitHub Repository: jajbshjahavahh/Gojo-Satoru
Path: blob/master/lib/math.js
2591 views
1
//═══════════════════════════════════════════════════════//
2
//If you want to recode, reupload
3
//or copy the codes/script,
4
//pls give credit
5
//no credit? i will take action immediately
6
//© 2022 Xeon Bot Inc. Cheems Bot MD
7
//Thank you to Lord Buddha, Family and Myself
8
//════════════════════════════//
9
let modes = {
10
noob: [-3, 3,-3, 3, '+-', 15000, 10],
11
easy: [-10, 10, -10, 10, '*/+-', 20000, 40],
12
medium: [-40, 40, -20, 20, '*/+-', 40000, 150],
13
hard: [-100, 100, -70, 70, '*/+-', 60000, 350],
14
extreme: [-999999, 999999, -999999, 999999, '*/', 99999, 9999],
15
impossible: [-99999999999, 99999999999, -99999999999, 999999999999, '*/', 30000, 35000],
16
impossible2: [-999999999999999, 999999999999999, -999, 999, '/', 30000, 50000]
17
}
18
19
let operators = {
20
'+': '+',
21
'-': '-',
22
'*': '×',
23
'/': '÷'
24
}
25
26
function randomInt(from, to) {
27
if (from > to) [from, to] = [to, from]
28
from = Math.floor(from)
29
to = Math.floor(to)
30
return Math.floor((to - from) * Math.random() + from)
31
}
32
33
function pickRandom(list) {
34
return list[Math.floor(Math.random() * list.length)]
35
}
36
37
function genMath(mode) {
38
return new Promise((resolve, reject) => {
39
let [a1, a2, b1, b2, ops, time, bonus] = modes[mode]
40
let a = randomInt(a1, a2)
41
let b = randomInt(b1, b2)
42
let op = pickRandom([...ops])
43
let result = (new Function(`return ${a} ${op.replace('/', '*')} ${b < 0 ? `(${b})` : b}`))()
44
if (op == '/') [a, result] = [result, a]
45
hasil = {
46
soal: `${a} ${operators[op]} ${b}`,
47
mode: mode,
48
waktu: time,
49
hadiah: bonus,
50
jawaban: result
51
}
52
resolve(hasil)
53
})
54
}
55
56
module.exports = { modes, operators, randomInt, pickRandom, genMath }
57
58