Skip to content

Commit f2a31b4

Browse files
committed
finished calc
1 parent 3c581e8 commit f2a31b4

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

2-calc/calc.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
var math = require('./math');
1+
var math = require("./math");
22

33
var command = process.argv[2];
4-
var arguments = process.argv.slice(3).map(function(arg) {
5-
return parseFloat(arg);
6-
});
4+
var num1 = parseFloat(process.argv[3]);
5+
var num2 = parseFloat(process.argv[4]);
76

8-
if (math[command]) {
9-
console.log("running:", command);
10-
console.log(math[command].apply(math, arguments));
11-
} else {
12-
console.log("command " + command + " not found!");
13-
console.log("allowed commands are: ", Object.keys(math).join(', '));
14-
}
7+
console.log(math[command](num1, num2));

2-calc/math.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
module.exports = {
2-
add: function(x, y) {
3-
return x+y;
4-
},
5-
subtract: function(x, y) {
6-
return x-y;
2+
multiply: function(x, y) {
3+
return x * y;
74
},
8-
squareRoot: function(x) {
9-
return Math.sqrt(x);
5+
add: function(x, y) {
6+
return x + y;
107
}
118
};

0 commit comments

Comments
 (0)