daco2020 2022. 3. 4. 12:43

Description:

Implement a function that accepts 3 integer values a, b, c. The function should return true if a triangle can be built with the sides of given length and false in any other case.

(In this case, all triangles must have surface greater than 0 to be accepted).

 

 

Solution:

1. Sort a, b, c in ascending order.
2. Compare the last number (largest number) with the sum of the remaining two numbers.
3. If it is equal to or greater than, false is returned, otherwise true is returned.

 

 

function isTriangle(a,b,c){
  let arr = [a,b,c].sort((a, b) => a - b);
  return arr[0] + arr[1] <= arr[2] ? false : true
}