(mode)
| 85 | } |
| 86 | }; |
| 87 | function 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 | } |
| 99 | function randomInt(from, to) { |
| 100 | if (from > to) |
| 101 | [from, to] = [to, from]; |
no test coverage detected