src/index.js
function computeRateBetweenSubunitAmounts(fromCurrency, fromAmount, toCurrency, toAmount) {
  /*
   * If currencies are equal, rate is 1
   */
  if (fromCurrency === toCurrency) {
    return 1;
  }

  /*
   * If toAmount is 0, we don't want to divide by zero.
   * In this case, return NaN
   */
  if (toAmount === 0) {
    return NaN;
  }

  /*
   * Convert both amounts to main units
   */
  const fromAmountMainUnit = fromSmallestSubunit(fromAmount, fromCurrency);
  const toAmountMainUnit = fromSmallestSubunit(toAmount, toCurrency);

  /*
   * Compute and return rate
   */
  return fromAmountMainUnit / toAmountMainUnit;
}
function computeRateBetweenSubunitAmounts(fromCurrency, fromAmount, toCurrency, toAmount) {
  /*
   * If currencies are equal, rate is 1
   */
  if (fromCurrency === toCurrency) {
    return 1;
  }

  /*
   * If toAmount is 0, we don't want to divide by zero.
   * In this case, return NaN
   */
  if (toAmount === 0) {
    return NaN;
  }

  /*
   * Convert both amounts to main units
   */
  const fromAmountMainUnit = fromSmallestSubunit(fromAmount, fromCurrency);
  const toAmountMainUnit = fromSmallestSubunit(toAmount, toCurrency);

  /*
   * Compute and return rate
   */
  return fromAmountMainUnit / toAmountMainUnit;
}
function computeRateBetweenSubunitAmounts ( fromCurrency , fromAmount , toCurrency , toAmount ) { /*
   * If currencies are equal, rate is 1
   */ if ( fromCurrency === toCurrency ) { return 1 ; } /*
   * If toAmount is 0, we don't want to divide by zero.
   * In this case, return NaN
   */ if ( toAmount === 0 ) { return NaN ; } /*
   * Convert both amounts to main units
   */ const fromAmountMainUnit = fromSmallestSubunit ( fromAmount , fromCurrency ) ; const toAmountMainUnit = fromSmallestSubunit ( toAmount , toCurrency ) ; /*
   * Compute and return rate
   */ return fromAmountMainUnit / toAmountMainUnit ; }
Computes a rate between two amounts in two different currencies.

The result is fromAmount / toAmount (in the main units of their respective currencies)

@param {string} fromCurrency
@param {int} fromAmount Amount denominated in smallest sub-unit of fromCurrency
@param {string} toCurrency
@param {int} toAmount Amount denominated in smallest sub-unit of toCurrency
Computes a rate between two amounts in two different currencies .