Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5338769

Browse filesBrowse files
Operation to sum infinite number is working well
1 parent 74bf53c commit 5338769
Copy full SHA for 5338769

File tree

4 files changed

+43
-13
lines changed
Filter options

4 files changed

+43
-13
lines changed

‎operations/operations.js

Copy file name to clipboard
+21-5Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
const add = function (a, b){
2-
return (typeof a === "number" && typeof b === "number") ?
3-
a + b :
4-
false;
5-
}
1+
const add = function(a, b) {
2+
return typeof a === "number" && typeof b === "number" ? a + b : false;
3+
};
64

5+
const addAll = function() {
6+
let total = 0;
7+
for (let arg in arguments) {
8+
9+
let loop = typeof arguments[arg] === "number";
10+
11+
if (!loop) {
12+
throw new Error("Only Numbers are allowed");
13+
} else {
14+
total += arguments[arg];
15+
}
16+
}
17+
return total;
18+
};
19+
20+
//console.log(addAll(11, false, 3, 4, 5, 6, 7, 8, 8, 9, 10));
21+
22+
module.exports = { add, addAll };

‎operations/operations.test.js

Copy file name to clipboardExpand all lines: operations/operations.test.js
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ describe("Testing Add implementation", () => {
1616
//Testing for AddAll Operation
1717
describe("Add operation for Infinite numbers", () => {
1818
it("Addition of 1 and 1 equals 2", () => {
19-
expect(add([1, 1])).toBe(2);
19+
expect(addAll(1, 1)).toBe(2);
2020
});
2121
it("Addition of multiple value", () => {
22-
expect(add([1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10])).toBe(385);
22+
expect(addAll(11, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10)).toBe(73);
2323
});
2424
it("Parameter should only be Numbers", () => {
25-
expect(add([" ", 2, 3, 4, 5, 6, 7, 8, 8, 9, 10])).toBeFalsy();
25+
function logError() {
26+
addAll([], 2, 3, 4, 5, 6, 7, 8, 8, 9, 10);
27+
}
28+
expect(logError).toThrowError(Error);
2629
});
27-
});
30+
});

‎operations/tempCodeRunnerFile.js

Copy file name to clipboard
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
const a = typeof(34);
2-
const b = "number"
1+
const addAll = function() {
2+
let total = 0;
3+
for (let arg in arguments) {
4+
if (!isNaN(arguments[arg])) {
5+
total += arguments[arg];
6+
} else {
7+
console.log(arguments[arg])
8+
throw new Error("Only Numbers are allowed");
9+
continue;
10+
}
11+
}
12+
return total;
13+
};
314

4-
console.log(a === b)
15+
console.log(addAll(11, false, 3, 4, 5, 6, 7, 8, 8, 9, 10));

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "jest"
7+
"test": "jest --watchAll"
88
},
99
"repository": {
1010
"type": "git",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.