UNPKG

sb-game

Version:
39 lines (28 loc) 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.getGreaterDivisor = void 0; var _ = _interopRequireDefault(require("..")); var _utils = require("../utils"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const gameConditions = 'Find the greatest common divisor of given numbers.'; const getGreaterDivisor = (a, b) => { if (b === 0) { return a; } return getGreaterDivisor(b, a % b); }; exports.getGreaterDivisor = getGreaterDivisor; const getGameData = () => { const num1 = (0, _utils.getRandom)(2, 101); const num2 = (0, _utils.getRandom)(2, 101); const question = `${num1} ${num2}`; const answer = String(getGreaterDivisor(num1, num2)); return (0, _utils.cons)(question, answer); }; var _default = () => { (0, _.default)(gameConditions, getGameData); }; exports.default = _default; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nYW1lcy9nY2QuanMiXSwibmFtZXMiOlsiZ2FtZUNvbmRpdGlvbnMiLCJnZXRHcmVhdGVyRGl2aXNvciIsImEiLCJiIiwiZ2V0R2FtZURhdGEiLCJudW0xIiwibnVtMiIsInF1ZXN0aW9uIiwiYW5zd2VyIiwiU3RyaW5nIl0sIm1hcHBpbmdzIjoiOzs7Ozs7O0FBQUE7O0FBQ0E7Ozs7QUFFQSxNQUFNQSxjQUFjLEdBQUcsb0RBQXZCOztBQUVPLE1BQU1DLGlCQUFpQixHQUFHLENBQUNDLENBQUQsRUFBSUMsQ0FBSixLQUFVO0FBQ3pDLE1BQUlBLENBQUMsS0FBSyxDQUFWLEVBQWE7QUFDWCxXQUFPRCxDQUFQO0FBQ0Q7O0FBRUQsU0FBT0QsaUJBQWlCLENBQUNFLENBQUQsRUFBSUQsQ0FBQyxHQUFHQyxDQUFSLENBQXhCO0FBQ0QsQ0FOTTs7OztBQVFQLE1BQU1DLFdBQVcsR0FBRyxNQUFNO0FBQ3hCLFFBQU1DLElBQUksR0FBRyxzQkF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