up
This commit is contained in:
parent
5372c18379
commit
3defacc09d
314 changed files with 1761 additions and 1704 deletions
|
@ -0,0 +1,29 @@
|
|||
function Calculator() {
|
||||
|
||||
var methods = {
|
||||
"-": function(a, b) {
|
||||
return a - b;
|
||||
},
|
||||
"+": function(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
};
|
||||
|
||||
this.calculate = function(str) {
|
||||
|
||||
var split = str.split(' '),
|
||||
a = +split[0],
|
||||
op = split[1],
|
||||
b = +split[2]
|
||||
|
||||
if (!methods[op] || isNaN(a) || isNaN(b)) {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
return methods[op](a, b);
|
||||
}
|
||||
|
||||
this.addMethod = function(name, func) {
|
||||
methods[name] = func;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue