Created
July 20, 2018 10:53
-
-
Save breeko/82cc3974c3527fc242b4b84b9cb69e67 to your computer and use it in GitHub Desktop.
setOperand function for OpenCalc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setOperand(op: Operation): ?Operation { | |
| let newNumber: ?string; | |
| if (!Validator.validDigit(op.stringVal, this.queue)) { | |
| return null; | |
| } | |
| let lastOp: ?Operation = lastOrNull(this.queue); | |
| if (lastOp && ( | |
| this.cleared || | |
| lastOp.operationArgs.has(OperationArgs.NotParseable) || | |
| op.operationArgs.has(OperationArgs.NotParseable) && lastOp.operationType === OperationType.Constant) | |
| ) { | |
| this.queue.pop(); | |
| } else if (lastOp && lastOp.operationType === OperationType.Constant) { | |
| const lastNumber = this.queue.pop(); | |
| newNumber = lastNumber.stringVal + op.stringVal; | |
| } | |
| if (newNumber) { | |
| return newOperation(newNumber, this.queue); | |
| } else { | |
| return op; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment