SafychCSS/project-lvl1-s474

View on GitHub
src/games/gcd.js

Summary

Maintainability
A
0 mins
Test Coverage
import runGame from '..';
import getRandomNumber from '../utils';

const condition = 'Find the greatest common divisor of given numbers.';

const getGcd = (a, b) => {
  if (b === 0) {
    return a;
  }
  return getGcd(b, a % b);
};

const generateRound = () => {
  const num1 = getRandomNumber(1, 10);
  const num2 = getRandomNumber(1, 10);
  const question = `${num1} ${num2}`;
  const answer = String(getGcd(num1, num2));
  return [question, answer];
};
export default () => runGame(condition, generateRound);