Last active
August 29, 2015 14:03
-
-
Save nadeesha/7a7a5430d8a526979293 to your computer and use it in GitHub Desktop.
Codility Answers in Javascript
This file contains 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
// you can use console.log for debugging purposes, i.e. | |
// console.log('this is a debug message'); | |
function solution(A) { | |
A.sort(function(a,b) { | |
if (a < b) { | |
return 1; | |
} else if (a > b) { | |
return -1; | |
} else { | |
return 0; | |
} | |
}); | |
return Math.max(A[0]*A[1]*A[2], A[A.length-1] * A[A.length-2] * A[0]); | |
} |
This file contains 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
// you can use console.log for debugging purposes, i.e. | |
// console.log('this is a debug message'); | |
function solution(A) { | |
A.sort(function(a,b) { | |
if (a > b) { | |
return 1; | |
} else if (a < b) { | |
return -1; | |
} else { | |
return 0; | |
} | |
}); | |
for(var i=0; i < A.length-2; i++) { | |
if (A[i] + A[i+1] > A[i+2]) { | |
return 1; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment