Skip to content

Instantly share code, notes, and snippets.

@GIBZ-GIPE
Last active March 23, 2021 14:33
Show Gist options
  • Save GIBZ-GIPE/a0fb235a082ff02d781aaa8cd419a875 to your computer and use it in GitHub Desktop.
Save GIBZ-GIPE/a0fb235a082ff02d781aaa8cd419a875 to your computer and use it in GitHub Desktop.
class Calculator {
double _lastResult = 0;
double subtract(double a, [double b]) {
if (b != null) {
_lastResult = a - b;
} else {
_lastResult -= a;
}
return _lastResult;
}
}
void main() {
var calc = Calculator();
print(calc.subtract(5, 2)); // 5 - 2 = 3
print(calc.subtract(1)); // 3 - 1 = 2
print(calc.subtract(10, 9)); // 10 - 9 = 1
print(calc.subtract(1)); // 1 - 1 = 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment