packages/solver/lib/util/flattenOperands.js
function flattenDivision(node) {
  // We recurse on the left side of the tree to find operands so far
  // Flattening division is always considered part of a bigger picture
  // of multiplication, so we get operands with '*'
  let operands = getOperands(node.args[0], '*');

  if (operands.length === 1) {
    node.args[0] = operands.pop();
    node.args[1] = flattenOperands(node.args[1]);
    operands = [node];
  }
  else {
    // This is the last operand, the term we'll want to add our division to
    const numerator = operands.pop();
    // This is the denominator of the current division node we're recursing on
    const denominator = flattenOperands(node.args[1]);
    // Note that this means 2 * 3 * 4 / 5 / 6 * 7 will flatten but keep the 4/5/6
    // as an operand - in simplifyDivision.js this is changed to 4/(5*6)
    const divisionNode = Node.Creator.operator('/', [numerator, denominator]);
    operands.push(divisionNode);
  }

  return operands;
}
function flattenDivision(node) {
  // We recurse on the left side of the tree to find operands so far
  // Flattening division is always considered part of a bigger picture
  // of multiplication, so we get operands with '*'
  let operands = getOperands(node.args[0], '*');

  if (operands.length === 1) {
    node.args[0] = operands.pop();
    node.args[1] = flattenOperands(node.args[1]);
    operands = [node];
  }
  else {
    // This is the last operand, the term we'll want to add our division to
    const numerator = operands.pop();
    // This is the denominator of the current division node we're recursing on
    const denominator = flattenOperands(node.args[1]);
    // Note that this means 2 * 3 * 4 / 5 / 6 * 7 will flatten but keep the 4/5/6
    // as an operand - in simplifyDivision.js this is changed to 4/(5*6)
    const divisionNode = Node.Creator.operator('/', [numerator, denominator]);
    operands.push(divisionNode);
  }

  return operands;
}
function flattenDivision ( node ) { // We recurse on the left side of the tree to find operands so far // Flattening division is always considered part of a bigger picture // of multiplication, so we get operands with '*' let operands = getOperands ( node . args [ 0 ] , '*' ) ; if ( operands . length === 1 ) { node . args [ 0 ] = operands . pop ( ) ; node . args [ 1 ] = flattenOperands ( node . args [ 1 ] ) ; operands = [ node ] ; } else { // This is the last operand, the term we'll want to add our division to const numerator = operands . pop ( ) ; // This is the denominator of the current division node we're recursing on const denominator = flattenOperands ( node . args [ 1 ] ) ; // Note that this means 2 * 3 * 4 / 5 / 6 * 7 will flatten but keep the 4/5/6 // as an operand - in simplifyDivision.js this is changed to 4/(5*6) const divisionNode = Node . Creator . operator ( '/' , [ numerator , denominator ] ) ; operands . push ( divisionNode ) ; } return operands ; }
Takes a division node and returns a list of operands If there is multiplication in the numerator, the operands returned are to be multiplied together. Otherwise, a list of length one with just the division node is returned. getOperands might change the operator accordingly.
Takes a division node and returns a list of operands If there is multiplication in the numerator the operands returned are to be multiplied together . Otherwise a list of length one with just the division node is returned . getOperands might change the operator accordingly .