Skip to content

Instantly share code, notes, and snippets.

@dolvik
Created May 31, 2016 09:16
Show Gist options
  • Save dolvik/078496f9291b29fefde9281d078553c3 to your computer and use it in GitHub Desktop.
Save dolvik/078496f9291b29fefde9281d078553c3 to your computer and use it in GitHub Desktop.
Triangle. Determine whether a triangle can be built from a given set of edges.
//http://codility.com/demo/take-sample-test/triangle
function solution(arr) {
if (arr.length < 3){
return 0;
}
arr.sort(function(a, b){return a - b;});
for (var i = 0, len = arr.length; i < len - 2; i++){
if (arr[i] + arr[i + 1] > arr[i + 2]){
return 1;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment