Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Created March 30, 2013 05:43
Show Gist options
  • Save JogoShugh/5275545 to your computer and use it in GitHub Desktop.
Save JogoShugh/5275545 to your computer and use it in GitHub Desktop.
Simple calculator
Calculator.prototype.add = function () {
var result = 0;
for (var i = 0, j = arguments.length; i < j; i++) {
result += parseFloat(arguments[i]);
}
return result;
};
function Calculator() {
}
Calculator.prototype.subtract = function () {
var result = 0;
if (arguments.length > 0) result = arguments[0];
for (var i = 1, j = arguments.length; i < j; i++) {
result -= parseFloat(arguments[i]);
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment