File tree 2 files changed +5
-3
lines changed
2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change 8
8
export function maxProductOfThree ( arrayItems ) {
9
9
// if size is less than 3, no triplet exists
10
10
let n = arrayItems . length
11
- if ( n < 3 ) return - 1
11
+ if ( n < 3 ) throw new Error ( 'Triplet cannot exist with the given array' )
12
12
let max1 = arrayItems [ 0 ] ,
13
13
max2 = - 1 ,
14
14
max3 = - 1 ,
Original file line number Diff line number Diff line change 1
1
import { maxProductOfThree } from '../MaxProductOfThree'
2
2
3
3
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' )
6
8
} )
7
9
8
10
it ( 'expects to return 300 as the maximum product' , ( ) => {
You can’t perform that action at this time.
0 commit comments