Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
Created April 7, 2016 08:05
Show Gist options
  • Save mmloveaa/3b4975b1187b8a348afe75132fae07e9 to your computer and use it in GitHub Desktop.
Save mmloveaa/3b4975b1187b8a348afe75132fae07e9 to your computer and use it in GitHub Desktop.
4- 6 - Q28 -Highest Product
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