Codility: Triangle Solution
Lesson 6 Sorting1function solution(A) {2 if (A.length < 3) {3 return 04 }56 function isTriangle(a, b, c) {7 return (a > 0) & (b > 0) & (c > 0) && a + b > c && a + c > b && b + c > a8 }910 A.sort((a, b) => a - b)1112 let count = 013 for (let i = 0; i < A.length - 2; i++) {14 if (!isTriangle(A[i], A[i + 1], A[i + 2])) {15 count++16 }17 }1819 return count === A.length - 2 ? 0 : 120}
Comments
Loading comments...
Tags
codility
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
Codility: NumberOfDiscIntersections
Lesson 6 Sorting