본문 바로가기

■ 프로그래밍/알고리즘

[JS] Is this a triangle?

[ 문제 ]

Implement a method that accepts 3 integer values a, b, c. The method 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).

 

 

[ 내 풀이 ]

 

2020.10.30 (10m)

function isTriangle(a, b, c) { 
  const sortArr = [a, b, c].sort() 
  if (sortArr[2] < sortArr[0] + sortArr[1]) return true 
  return false 
}

가장 긴 변의 길이가 나머지 두개의 변 길이 합 보다 작으면 삼각형 성립

 

출처: CodeWars

 

'■ 프로그래밍 > 알고리즘' 카테고리의 다른 글

[JS] Who likes it?  (0) 2020.11.11
[JS] Mumbling  (0) 2020.11.10
[JS] Isograms  (0) 2020.11.06
[JS] 가장 넓은 면적 구하기  (0) 2020.04.17
[JS] 특정 수가 나오는 index 찾기  (0) 2020.04.07