added throwing an error when array with <3 items is passed

This commit is contained in:
devcer
2021-10-15 21:49:29 +05:30
parent b3377bb79c
commit 67ec915d97
2 changed files with 5 additions and 3 deletions

View File

@ -8,7 +8,7 @@
export function maxProductOfThree(arrayItems) {
// if size is less than 3, no triplet exists
let n = arrayItems.length
if (n < 3) return -1
if (n < 3) throw new Error('Triplet cannot exist with the given array')
let max1 = arrayItems[0],
max2 = -1,
max3 = -1,