Skip to content

Commit 3c581e8

Browse files
committed
added 2-calc
1 parent dda2819 commit 3c581e8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

2-calc/calc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var math = require('./math');
2+
3+
var command = process.argv[2];
4+
var arguments = process.argv.slice(3).map(function(arg) {
5+
return parseFloat(arg);
6+
});
7+
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+
}

2-calc/math.js

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

0 commit comments

Comments
 (0)