MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / genMath

Function genMath

plugins/math.js:87–98  ·  view source on GitHub ↗
(mode)

Source from the content-addressed store, hash-verified

85 }
86};
87function genMath(mode) {
88 const [a1, a2, b1, b2, ops, time] = modes[mode];
89 let a = randomInt(a1, a2);
90 const b = randomInt(b1, b2);
91 const op = pickRandom([...ops]);
92 const expr = `${a} ${op.replace('/', '*')} ${b < 0 ? `(${b})` : b}`;
93 // eslint-disable-next-line no-eval
94 let result = eval(expr);
95 if (op === '/')
96 [a, result] = [result, a];
97 return { str: `${a} ${operators[op]} ${b}`, mode, time, result };
98}
99function randomInt(from, to) {
100 if (from > to)
101 [from, to] = [to, from];

Callers 1

handlerFunction · 0.85

Calls 2

randomIntFunction · 0.85
pickRandomFunction · 0.70

Tested by

no test coverage detected