Last active
September 24, 2015 15:47
-
-
Save jpavley/085db3b177e3398c6a4e to your computer and use it in GitHub Desktop.
code from CS193P: Developing iOS 8 Applications with Swift that longer compiles with the solution
This file contains 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
// bad code | |
func performOperationWith(operation: (Double, Double) -> Double) { | |
if operandStack.count >= 2 { | |
displayValue = operation(operandStack.removeLast(), operandStack.removeLast()) | |
enter() | |
} | |
} | |
func performOperation(operation: Double -> Double) { | |
if operandStack.count >= 1 { | |
displayValue = operation(operandStack.removeLast()) | |
enter() | |
} | |
} | |
// good code | |
func performOperationWithTwoOperands(operation: (Double, Double) -> Double) { | |
if operandStack.count >= 2 { | |
displayValue = operation(operandStack.removeLast(), operandStack.removeLast()) | |
enter() | |
} | |
} | |
func performOperationWithOneOperand(operation: Double -> Double) { | |
if operandStack.count >= 1 { | |
displayValue = operation(operandStack.removeLast()) | |
enter() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment