Created
June 16, 2018 16:01
-
-
Save adicuco/2a864bce8a4e4bf5d035951106dcc3d7 to your computer and use it in GitHub Desktop.
100% solution for Maximum Product of Three Task on Codility
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 solution(A) { | |
| A.sort(function(a, b) { | |
| return a - b; | |
| }); | |
| var max1 = A[A.length - 1] * A[A.length - 2] * A[A.length - 3]; | |
| var max2 = A[A.length - 1] * A[0] * A[1]; | |
| return max1 > max2 ? max1 : max2; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment