-
Notifications
You must be signed in to change notification settings - Fork 0
/
brain-progression.js
40 lines (34 loc) · 1.15 KB
/
brain-progression.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import generateRandomNum from '../generaterandomnum.js';
import { getEngine, roundsCount } from '../index.js';
const gameRules = 'What number is missing in the progression?';
const progressionLength = 7;
const getProgression = (start, step) => {
const progression = [];
for (let i = 0; i < progressionLength; i += 1) {
progression.push(start + step * i);
}
return progression;
};
const getHideSymbol = (arrOfProgression, index) => {
const progressionCopy = arrOfProgression.slice();
progressionCopy[index] = '..';
const question = progressionCopy.join(' ');
return question;
};
const generateOneRound = () => {
const index = generateRandomNum(0, progressionLength - 1);
const start = generateRandomNum(1, 100);
const step = generateRandomNum(1, 10);
const progression = getProgression(start, step);
const answer = progression[index];
const question = getHideSymbol(progression, index);
return [question, String(answer)];
};
const progressionGame = () => {
const gameData = [];
for (let i = 0; i < roundsCount; i += 1) {
gameData.push(generateOneRound());
}
getEngine(gameRules, gameData);
};
export default progressionGame;