Created
May 2, 2018 12:31
-
-
Save EJSohn/64feec7324f74bcf352641d097f932fb to your computer and use it in GitHub Desktop.
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
| func evaluate(_ expression: ArithmeticExpression) -> Int { | |
| switch expression { | |
| case let .number(value): | |
| return value | |
| case let .addition(left, right): | |
| return evaluate(left) + evaluate(right) | |
| case let .multiplication(left, right): | |
| return evaluate(left) * evaluate(right) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment