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

Sign up
Appearance settings

Commit 67ec915

Browse files
committed
added throwing an error when array with <3 items is passed
1 parent b3377bb commit 67ec915

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

‎Dynamic-Programming/MaxProductOfThree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
export function maxProductOfThree(arrayItems) {
99
// if size is less than 3, no triplet exists
1010
let n = arrayItems.length
11-
if (n < 3) return-1
11+
if (n < 3) thrownewError('Triplet cannot exist with the given array')
1212
let max1 = arrayItems[0],
1313
max2 = -1,
1414
max3 = -1,

‎Dynamic-Programming/tests/MaxProductOfThree.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { maxProductOfThree } from '../MaxProductOfThree'
22

33
describe('MaxProductOfThree', () => {
4-
it('expects to return -1 for array with only 2 numbers', () => {
5-
expect(maxProductOfThree([1, 3])).toBe(-1)
4+
it('expects to throw error for array with only 2 numbers', () => {
5+
expect(() => {
6+
maxProductOfThree([1, 3])
7+
}).toThrow('Triplet cannot exist with the given array')
68
})
79

810
it('expects to return 300 as the maximum product', () => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /