Skip to content

Instantly share code, notes, and snippets.

@nadeesha
Last active August 29, 2015 14:03
Show Gist options
  • Save nadeesha/7a7a5430d8a526979293 to your computer and use it in GitHub Desktop.
Save nadeesha/7a7a5430d8a526979293 to your computer and use it in GitHub Desktop.
Codility Answers in Javascript
// 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]);
}
// 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