// Program to find largest product yielded from three integers

function sortIntegers(a, b) {
	return a - b;
}

// greatest product either min1 * min2 * max1 OR max1 * max2 * max3
function largestProduct(unsortedArray) {
	var sortedArray = unsortedArray.sort(sortIntegers),
		productOne = 1,
		productTwo = 1,
		lastElementIndex = sortedArray.length - 1;

	// get product of three largest integers in sorted array
	for (var i = lastElementIndex; i > lastElementIndex - 3; i--) {
		productOne = productOne * sortedArray[i];
	}

	productTwo = sortedArray[0] * sortedArray[1] * sortedArray[lastElementIndex];

	if (productOne > productTwo) {
		return productOne;
	}

	return productTwo;
}

@@ -112,13 +112,12 @@
 %0A// 
-great
+larg
 est 
@@ -128,16 +128,22 @@
 uct 
+yield 
 either m
 in1 
@@ -142,47 +142,47 @@
 er m
-in
+ax
 1 * m
-in
+ax
 2 * max
-1
+3
  OR m
-ax
+in
 1 * m
-ax
+in
 2 * max
-3
+1
 %0Afun
@@ -520,20 +520,90 @@
 rray%5Bi%5D;
-%0A%09%7D%0A
+ // first case: max1 * max2 * max3%0A%09%7D%0A%0A%09// second case: min1 * min2 * max1
 %0A%09produc
@@ -675,16 +675,83 @@
 ndex%5D;%0A%0A
+%09// compare first and second cases and return larger product yield%0A
 %09if (pro
@@ -817,12 +817,99 @@
 oductTwo;%0A%7D%0A
+%0A// test case%0AlargestProduct(%5B-10, 7, 29, 30, 5, -10, -70%5D); // expect to return 21000%0A

Add test case