UNPKG

brain-game

Version:
38 lines (28 loc) 1.03 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _ = require('../'); var _2 = _interopRequireDefault(_); var _utils = require('../utils'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const description = 'What number is missing in this progression?\n'; const generate = () => { const start = (0, _utils.getCustomRandomInt)(); const step = (0, _utils.getRandomInt)(0, 10); const points = (0, _utils.getRandomInt)(2, 9); const seq = [start]; for (let i = 0; i < 10; i += 1) { seq.push(seq[seq.length - 1] + step); } seq[points] = '..'; return seq.slice(); }; const target = array => { const indexLast = array.findIndex(item => item === '..') - 1; const indexFirst = indexLast - 1; const step = array[indexLast] - array[indexFirst]; return array[indexLast] + step; }; const toString = array => array.toString().split(',').join(' '); exports.default = () => (0, _2.default)(description, generate, target, toString);