Skip to content

Commit 2dbb7d7

Browse files
All joinString operation test cases pass
1 parent c269bac commit 2dbb7d7

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

operations/arithmethics/operations.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//Addition Operation
22
const twoSum = function(a, b) {
33
return arguments.length < 2 || arguments.length > 3
4-
? "Input only two Numbers"
5-
: typeof a === "number" && typeof b === "number"
6-
? a + b
7-
: "Inputs Must be Numbers";
4+
? "Input only two Numbers"
5+
: typeof a === "number" && typeof b === "number"
6+
? a + b
7+
: "Inputs Must be Numbers";
88
};
99

1010
//Adding Infinite sum of numbers
@@ -25,10 +25,10 @@ const addAll = function() {
2525
//Subraction Operation
2626
const subtract = function(a, b) {
2727
return arguments.length < 2 || arguments.length > 3
28-
? "Input only two Numbers"
29-
: typeof a === "number" && typeof b === "number"
30-
? a - b
31-
: "Inputs Must be Numbers";
28+
? "Input only two Numbers"
29+
: typeof a === "number" && typeof b === "number"
30+
? a - b
31+
: "Inputs Must be Numbers";
3232
};
3333

3434
//Multiplication Operation
@@ -49,15 +49,19 @@ const multiply = function() {
4949
//Division Operation
5050
const divide = function(a, b) {
5151
return arguments.length < 2 || arguments.length > 3
52-
? "Input only two Numbers"
53-
: typeof a === "number" && typeof b === "number"
54-
? a / b
55-
: "Inputs Must be Numbers";
52+
? "Input only two Numbers"
53+
: typeof a === "number" && typeof b === "number"
54+
? a / b
55+
: "Inputs Must be Numbers";
5656
};
5757

5858
//String Concatenation Operation
5959
const joinString = function(a, b) {
60-
return typeof a === "string" && typeof b === "string" ? a.concat(b) : false;
60+
return arguments.length < 2 || arguments.length > 3
61+
? "Input only two String"
62+
: typeof a === "string" && typeof b === "string"
63+
? a.concat(b)
64+
: "Inputs Must be String";
6165
};
6266

6367
module.exports = { twoSum, addAll, subtract, multiply, divide, joinString };

operations/arithmethics/operations.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ describe("Testing String Concatenation implementation", () => {
111111
expect(joinString("Good", "Job")).toBe("GoodJob");
112112
});
113113
it("Parameter should only be String", () => {
114-
expect(joinString("Well", 4)).toBeFalsy();
114+
expect(joinString("Well", 4)).toMatch(/Must be String/);
115+
});
116+
it("Parameter should at least be two", () => {
117+
expect(joinString("Well")).toMatch(/only two String/);
118+
});
119+
it("Parameter should not be more than two", () => {
120+
expect(joinString("Good", "Job", "Well", "Done")).toMatch(/only two String/);
115121
});
116122
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy