Skip to content

Commit 206f7c9

Browse files
committed
merge
1 parent 17e0d9e commit 206f7c9

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,23 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct
6262

6363
- [Caeser Cipher](src/_Classics_/caeser_cipher)
6464
- [Fibonacci](src/_Classics_/fibonacci)
65+
66+
---
67+
68+
## CONTRIBUTION Guide
69+
70+
It's great to know that you want to contribute to this repo. Thanks for taking interest. Before you start, read the following carefully.
71+
72+
- When adding a new **problem** with solution
73+
- Take care of the filename convention (Very Important)
74+
- Problem statement should be there with examples
75+
- Make sure you add the Run Time complexity of your solution
76+
- Please take care of the segregation of the Problems as per the given Folder Structure
77+
- It's great if you can add the **Unit Tests** to verify your solutions as well
78+
- Strictly follow ESLINT rules
79+
80+
- When adding a Unit Test
81+
- Take care of the file name convention
82+
- Make sure CI (Travis) is passing
83+
84+
Keep an eye on this guide, it's subjected to change frequently.

src/_Problems_/max-product-of-3-numbers/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ function maxProductof3NumbersII(arr) {
6363

6464
return p1 > p2 ? p1 : p2;
6565
}
66+
67+
module.exports = { maxProductof3Numbers, maxProductof3NumbersII };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const { maxProductof3Numbers, maxProductof3NumbersII } = require(".");
2+
3+
describe("Maximum Product of three numbers", () => {
4+
it("throws an error with no Array is passed", () => {
5+
expect(() => {
6+
maxProductof3Numbers("xunda");
7+
}).toThrowError();
8+
expect(() => {
9+
maxProductof3NumbersII("xunda");
10+
}).toThrowError();
11+
});
12+
13+
it("returns the product of an array with 3 numbers", () => {
14+
expect(maxProductof3Numbers([1, 2, 3])).toEqual(6);
15+
expect(maxProductof3NumbersII([1, 2, 3])).toEqual(6);
16+
});
17+
18+
it("returns the product of an array with positive and negative numbers", () => {
19+
expect(maxProductof3Numbers([-10, -10, 2, 3])).toEqual(300);
20+
expect(maxProductof3NumbersII([-10, -10, 2, 3])).toEqual(300);
21+
});
22+
23+
it("returns the product of an array with negative numbers", () => {
24+
expect(maxProductof3Numbers([-10, -1, -2, -10])).toEqual(-20);
25+
expect(maxProductof3NumbersII([-10, -1, -2, -10])).toEqual(-20);
26+
});
27+
28+
it("returns the proper calculation if the array is large", () => {
29+
const largeArray = [100, 100, 100, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 45, 4, 3, 7, 8, 1, 3, 7, 8, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 45, 4, 3, 7, 8, 1, 3, 7, 8];
30+
expect(maxProductof3Numbers(largeArray)).toEqual(100 * 100 * 100);
31+
expect(maxProductof3NumbersII(largeArray)).toEqual(100 * 100 * 100);
32+
});
33+
34+
it("returns an error if there are less than 3 numbers", () => {
35+
expect(() => {
36+
maxProductof3Numbers([-10, -1]);
37+
}).toThrowError();
38+
});
39+
});

0 commit comments

Comments
 (0)