dist/vend-number.js
function _executeOperation(operation, values) {
  /**
   * Run passed method if value passed is not NaN, otherwise throw a TypeError.
   *
   * @private
   * @method _ifValid
   *
   * @param value {Number}
   *        A value to check is not NaN before running method on.
   *
   * @param method {Function}
   *        A method to run if value is not NaN.
   */
  function _ifValid(value, method) {
    if (!isNaN(value)) {
      method();
    } else {
      throw new TypeError('The VendNumber method must receive a valid String or Number. ' + value);
    }
  }

  // Ensure there's an initial value to start operations on.
  var returnValue = parseFloat(values[0]);

  // Then remove the element at index 0.
  values.splice(0, 1);

  // Convert to VendNumber
  _ifValid(returnValue, function () {
    return returnValue = new VendNumber(returnValue);
  });

  values.forEach(function (value) {
    value = parseFloat(value);

    _ifValid(value, function () {
      // Convert to VendNumber
      value = new VendNumber(value);
      // e.g. 5.plus(2) where 5 and 2 are VendNumber's
      returnValue = returnValue[operation](value);
    });
  });

  var operationAnswer = undefined;
  // Set the final result of the calculation as a standard Number.
  _ifValid(returnValue, function () {
    return operationAnswer = Number(returnValue.toString());
  });

  if (operationAnswer) {
    return operationAnswer;
  }

  // End value was not valid so value errors will be displayed but we return 0 to continue.
  return 0;
}
function _executeOperation(operation, values) {
  /**
   * Run passed method if value passed is not NaN, otherwise throw a TypeError.
   *
   * @private
   * @method _ifValid
   *
   * @param value {Number}
   *        A value to check is not NaN before running method on.
   *
   * @param method {Function}
   *        A method to run if value is not NaN.
   */
  function _ifValid(value, method) {
    if (!isNaN(value)) {
      method();
    } else {
      throw new TypeError('The VendNumber method must receive a valid String or Number. ' + value);
    }
  }

  // Ensure there's an initial value to start operations on.
  var returnValue = parseFloat(values[0]);

  // Then remove the element at index 0.
  values.splice(0, 1);

  // Convert to VendNumber
  _ifValid(returnValue, function () {
    return returnValue = new VendNumber(returnValue);
  });

  values.forEach(function (value) {
    value = parseFloat(value);

    _ifValid(value, function () {
      // Convert to VendNumber
      value = new VendNumber(value);
      // e.g. 5.plus(2) where 5 and 2 are VendNumber's
      returnValue = returnValue[operation](value);
    });
  });

  var operationAnswer = undefined;
  // Set the final result of the calculation as a standard Number.
  _ifValid(returnValue, function () {
    return operationAnswer = Number(returnValue.toString());
  });

  if (operationAnswer) {
    return operationAnswer;
  }

  // End value was not valid so value errors will be displayed but we return 0 to continue.
  return 0;
}
function _executeOperation ( operation , values ) { /**
   * Run passed method if value passed is not NaN, otherwise throw a TypeError.
   *
   * @private
   * @method _ifValid
   *
   * @param value {Number}
   *        A value to check is not NaN before running method on.
   *
   * @param method {Function}
   *        A method to run if value is not NaN.
   */ function _ifValid ( value , method ) { if ( ! isNaN ( value ) ) { method ( ) ; } else { throw new TypeError ( 'The VendNumber method must receive a valid String or Number. ' + value ) ; } } // Ensure there's an initial value to start operations on. var returnValue = parseFloat ( values [ 0 ] ) ; // Then remove the element at index 0. values . splice ( 0 , 1 ) ; // Convert to VendNumber _ifValid ( returnValue , function ( ) { return returnValue = new VendNumber ( returnValue ) ; } ) ; values . forEach ( function ( value ) { value = parseFloat ( value ) ; _ifValid ( value , function ( ) { // Convert to VendNumber value = new VendNumber ( value ) ; // e.g. 5.plus(2) where 5 and 2 are VendNumber's returnValue = returnValue [ operation ] ( value ) ; } ) ; } ) ; var operationAnswer = undefined ; // Set the final result of the calculation as a standard Number. _ifValid ( returnValue , function ( ) { return operationAnswer = Number ( returnValue . toString ( ) ) ; } ) ; if ( operationAnswer ) { return operationAnswer ; } // End value was not valid so value errors will be displayed but we return 0 to continue. return 0 ; }
Executes VendNumber calculation operation on an array of values.

@private
@method _executeOperation

@param operation {String}
The operation to perform on the VendNumber.

@param values {Array}
A list of values to perform the operation on (any length).

@return {Number} The final result or 0 if invalid.
Executes VendNumber calculation operation on an array of values .