lib/simplifyExpression/basicsSearch/removeAdditionOfZero.js
// remove 0 from the operands list. Returns a Node.Status object.
remove 0 from the operands list.
remove 0 from the operands list .
function removeAdditionOfZero(node) {
  if (node.op !== '+') {
    return Node.Status.noChange(node);
  }
  const zeroIndex = node.args.findIndex(arg => {
    return Node.Type.isConstant(arg) && arg.value === '0';
  });
  let newNode = node.cloneDeep();
  if (zeroIndex >= 0) {
    newNode.args.splice(zeroIndex, 1);
    if (newNode.args.length === 1) {
      newNode = newNode.args[0];
    }
    return Node.Status.nodeChanged(
      ChangeTypes.REMOVE_ADDING_ZERO, node, newNode);
  }
  return Node.Status.noChange(node);
}
function removeAdditionOfZero ( node ) { if ( node . op !== '+' ) { return Node . Status . noChange ( node ) ; } const zeroIndex = node . args . findIndex ( arg => { return Node . Type . isConstant ( arg ) && arg . value === '0' ; } ) ; let newNode = node . cloneDeep ( ) ; if ( zeroIndex >= 0 ) { newNode . args . splice ( zeroIndex , 1 ) ; if ( newNode . args . length === 1 ) { newNode = newNode . args [ 0 ] ; } return Node . Status . nodeChanged ( ChangeTypes . REMOVE_ADDING_ZERO , node , newNode ) ; } return Node . Status . noChange ( node ) ; }
remove 0 from the operands list.
remove 0 from the operands list .
// remove the 0 node // if there's only one operand left, there's nothing left to add it to, // so move it up the tree