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