Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge
  • Loading branch information
SumeetHaryani committed Oct 6, 2019
commit 206f7c9854eb94aa4e95b948670f8e5b3163677f
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,23 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct

- [Caeser Cipher](src/_Classics_/caeser_cipher)
- [Fibonacci](src/_Classics_/fibonacci)

---

## CONTRIBUTION Guide

It's great to know that you want to contribute to this repo. Thanks for taking interest. Before you start, read the following carefully.

- When adding a new **problem** with solution
- Take care of the filename convention (Very Important)
- Problem statement should be there with examples
- Make sure you add the Run Time complexity of your solution
- Please take care of the segregation of the Problems as per the given Folder Structure
- It's great if you can add the **Unit Tests** to verify your solutions as well
- Strictly follow ESLINT rules

- When adding a Unit Test
- Take care of the file name convention
- Make sure CI (Travis) is passing

Keep an eye on this guide, it's subjected to change frequently.
2 changes: 2 additions & 0 deletions src/_Problems_/max-product-of-3-numbers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ function maxProductof3NumbersII(arr) {

return p1 > p2 ? p1 : p2;
}

module.exports = { maxProductof3Numbers, maxProductof3NumbersII };
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { maxProductof3Numbers, maxProductof3NumbersII } = require(".");

describe("Maximum Product of three numbers", () => {
it("throws an error with no Array is passed", () => {
expect(() => {
maxProductof3Numbers("xunda");
}).toThrowError();
expect(() => {
maxProductof3NumbersII("xunda");
}).toThrowError();
});

it("returns the product of an array with 3 numbers", () => {
expect(maxProductof3Numbers([1, 2, 3])).toEqual(6);
expect(maxProductof3NumbersII([1, 2, 3])).toEqual(6);
});

it("returns the product of an array with positive and negative numbers", () => {
expect(maxProductof3Numbers([-10, -10, 2, 3])).toEqual(300);
expect(maxProductof3NumbersII([-10, -10, 2, 3])).toEqual(300);
});

it("returns the product of an array with negative numbers", () => {
expect(maxProductof3Numbers([-10, -1, -2, -10])).toEqual(-20);
expect(maxProductof3NumbersII([-10, -1, -2, -10])).toEqual(-20);
});

it("returns the proper calculation if the array is large", () => {
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];
expect(maxProductof3Numbers(largeArray)).toEqual(100 * 100 * 100);
expect(maxProductof3NumbersII(largeArray)).toEqual(100 * 100 * 100);
});

it("returns an error if there are less than 3 numbers", () => {
expect(() => {
maxProductof3Numbers([-10, -1]);
}).toThrowError();
});
});