@pranavkok/mathterm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +57 -0
- package/package.json +19 -0
package/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const prompt = require("prompt-sync")();
|
|
3
|
+
|
|
4
|
+
console.log("Calculating ...");
|
|
5
|
+
|
|
6
|
+
let task = prompt("mathterm > ");
|
|
7
|
+
|
|
8
|
+
while (task !== "done") {
|
|
9
|
+
task = task.trim();
|
|
10
|
+
const arr = task.split(' ');
|
|
11
|
+
if (arr[0] === "add") {
|
|
12
|
+
let sum = 0;
|
|
13
|
+
const n = arr.length;
|
|
14
|
+
for(let i=1 ; i<n ; i++){
|
|
15
|
+
sum += parseInt(arr[i]);
|
|
16
|
+
}
|
|
17
|
+
console.log(`Answer is ${sum}`);
|
|
18
|
+
} else if (arr[0] === "sub") {
|
|
19
|
+
let diff = parseInt(arr[1]);
|
|
20
|
+
const n = arr.length;
|
|
21
|
+
for(let i=2 ; i<n ; i++){
|
|
22
|
+
diff -= parseInt(arr[i]);
|
|
23
|
+
}
|
|
24
|
+
console.log(`Answer is ${diff}`);
|
|
25
|
+
} else if (arr[0] === "mul") {
|
|
26
|
+
let mul = 1;
|
|
27
|
+
const n = arr.length;
|
|
28
|
+
for(let i=1 ; i<n ; i++){
|
|
29
|
+
mul *= parseInt(arr[i]);
|
|
30
|
+
}
|
|
31
|
+
console.log(`Answer is ${mul}`);
|
|
32
|
+
} else if (arr[0] === "div") {
|
|
33
|
+
let div = parseInt(arr[1]);
|
|
34
|
+
const n = arr.length;
|
|
35
|
+
for(let i=2 ; i<n ; i++){
|
|
36
|
+
div /= parseInt(arr[i]);
|
|
37
|
+
}
|
|
38
|
+
console.log(`Answer is ${div}`);
|
|
39
|
+
} else if(arr[0] === "help"){
|
|
40
|
+
console.log(`
|
|
41
|
+
Commands:
|
|
42
|
+
add <n1> <n2> ... Add numbers e.g. add 1 2 3
|
|
43
|
+
sub <n1> <n2> ... Subtract numbers e.g. sub 10 3 2
|
|
44
|
+
mul <n1> <n2> ... Multiply numbers e.g. mul 2 3 4
|
|
45
|
+
div <n1> <n2> ... Divide numbers e.g. div 100 5 2
|
|
46
|
+
help Show this message
|
|
47
|
+
done Exit
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.log("Invalid command.use 'help' command for any kind of Help");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
task = prompt("mathterm > ");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log("Goodbye!");
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pranavkok/mathterm",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"mathtermcli": "index.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"prompt-sync": "^4.2.0"
|
|
18
|
+
}
|
|
19
|
+
}
|