lib/node/MixedNumber.js
// TODO: Add better support for mixed numbers in the future
Add better support for mixed numbers in the future
Add better support for mixed numbers in the future
function isMixedNumber(node) {
  if (!NodeType.isOperator(node, '/')) {
    return false;
  }
  if (node.args.length !== 2) {
    return false;
  }
  const numerator = node.args[0];
  const denominator = node.args[1];
  if (!(NodeType.isOperator(numerator, '*') && numerator.implicit)) {
    return false;
  }
  const numeratorFirstArg = NodeType.isUnaryMinus(numerator.args[0]) ?
        Negative.negate(numerator.args[0].args[0])
        : numerator.args[0];
  const numeratorSecondArg = NodeType.isParenthesis(numerator.args[1]) ?
        numerator.args[1].content
        : numerator.args[1];
  if (!(NodeType.isConstant(numeratorFirstArg) &&
        NodeType.isConstant(numeratorSecondArg))) {
    return false;
  }
  const denominatorValue = NodeType.isParenthesis(denominator) ?
        denominator.content
        : denominator;
  if (!NodeType.isConstant(denominatorValue)) {
    return false;
  }
  return true;
}
function isMixedNumber ( node ) { if ( ! NodeType . isOperator ( node , '/' ) ) { return false ; } if ( node . args . length !== 2 ) { return false ; } const numerator = node . args [ 0 ] ; const denominator = node . args [ 1 ] ; if ( ! ( NodeType . isOperator ( numerator , '*' ) && numerator . implicit ) ) { return false ; } const numeratorFirstArg = NodeType . isUnaryMinus ( numerator . args [ 0 ] ) ? Negative . negate ( numerator . args [ 0 ] . args [ 0 ] ) : numerator . args [ 0 ] ; const numeratorSecondArg = NodeType . isParenthesis ( numerator . args [ 1 ] ) ? numerator . args [ 1 ] . content : numerator . args [ 1 ] ; if ( ! ( NodeType . isConstant ( numeratorFirstArg ) && NodeType . isConstant ( numeratorSecondArg ) ) ) { return false ; } const denominatorValue = NodeType . isParenthesis ( denominator ) ? denominator . content : denominator ; if ( ! NodeType . isConstant ( denominatorValue ) ) { return false ; } return true ; }
TODO: Add better support for mixed numbers in the future
TODO : Add better support for mixed numbers in the future
// check for implicit multiplication between two constants in the numerator // first can be wrapped in unary minus // second one can be optionally wrapped in parenthesis // check for a constant in the denominator, // optionally wrapped in parenthesis