File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change 88export 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 ) throw new Error ( 'Triplet cannot exist with the given array' )
1212 let max1 = arrayItems [ 0 ] ,
1313 max2 = - 1 ,
1414 max3 = - 1 ,
Original file line number Diff line number Diff line change 11import { maxProductOfThree } from '../MaxProductOfThree'
22
33describe ( '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' , ( ) => {
You can’t perform that action at this time.
0 commit comments