Created
May 31, 2016 09:16
-
-
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.
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
//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