Created
April 7, 2016 08:05
-
-
Save mmloveaa/3b4975b1187b8a348afe75132fae07e9 to your computer and use it in GitHub Desktop.
4- 6 - Q28 -Highest Product
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getProduct(arr) { | |
arr1 = arr.sort(function(a,b){ | |
return b-a | |
}) | |
// console.log(arr1) | |
var leftMax = arr1[0] * arr1[1] * arr1[2]; | |
var rightMax = arr1[arr1.length-1] * arr1[arr1.length-2] * arr1[0] | |
return leftMax > rightMax ? leftMax : rightMax | |
// if(leftMax > rightMax) { | |
// return leftMax | |
// } else { | |
// return rightMax | |
// } | |
} | |
getProduct([1,2,3,4,-3,-5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment