function getCommonDivisor(firstNum, secondNum) {
  if (secondNum === 0) return firstNum;

  var remainder = parseInt(firstNum % secondNum);

  return getCommonDivisor(secondNum, remainder);
}

function getProbability (quantity, coinQuantity) {
  // 如果用户克币数是0
  if (quantity === 0) {
    return '0';
  }
  var divisor = getCommonDivisor(quantity, coinQuantity);
  var value = quantity / divisor;
  var value2 = coinQuantity / divisor;
  // 如果分子比分母大说明中奖概率是100%，那么返回中奖概率
  if (value >= value2) {
    return coinQuantity + '/' + coinQuantity;
  } else {
    return value + '/' + value2;
  }
}
module.exports = {
  getProbability
};
