npm run style result

This commit is contained in:
VinWare
2021-10-21 15:06:33 +05:30
parent fe56f54f82
commit 5ccfafecbb
3 changed files with 52 additions and 52 deletions

View File

@ -5,15 +5,15 @@
* @param {number[]} arrayItems
* @returns number
*/
export function maxProductOfThree(arrayItems) {
export function maxProductOfThree (arrayItems) {
// if size is less than 3, no triplet exists
let n = arrayItems.length
const n = arrayItems.length
if (n < 3) throw new Error('Triplet cannot exist with the given array')
let max1 = arrayItems[0],
max2 = -1,
max3 = -1,
min1 = arrayItems[0],
min2 = -1
let max1 = arrayItems[0]
let max2 = -1
let max3 = -1
let min1 = arrayItems[0]
let min2 = -1
for (let i = 1; i < n; i++) {
if (arrayItems[i] > max1) {
max3 = max2
@ -32,7 +32,7 @@ export function maxProductOfThree(arrayItems) {
min2 = arrayItems[i]
}
}
let prod1 = max1 * max2 * max3,
prod2 = max1 * min1 * min2
const prod1 = max1 * max2 * max3
const prod2 = max1 * min1 * min2
return Math.max(prod1, prod2)
}