アルゴリズム74-Is this a三角形?
3946 ワード
Q.
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).
A) function isTriangle(a,b,c)
{
if (a <= 0 || b <= 0 || c <= 0)
return false;
let arr = [a, b, c].sort((a, b) => a - b);
return arr[2] < arr[0] + arr[1];
}
other
新しい配列を作るのではなく、このように構造を分解することもできます!function isTriangle(a,b,c)
{
[a, b, c] = [a, b, c].sort((x, y) => x-y);
return a+b > c;
}
Reference
この問題について(アルゴリズム74-Is this a三角形?), 我々は、より多くの情報をここで見つけました
https://velog.io/@pearpearb/알고리즘-74-Is-this-a-triangle
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
function isTriangle(a,b,c)
{
if (a <= 0 || b <= 0 || c <= 0)
return false;
let arr = [a, b, c].sort((a, b) => a - b);
return arr[2] < arr[0] + arr[1];
}
other
新しい配列を作るのではなく、このように構造を分解することもできます!function isTriangle(a,b,c)
{
[a, b, c] = [a, b, c].sort((x, y) => x-y);
return a+b > c;
}
Reference
この問題について(アルゴリズム74-Is this a三角形?), 我々は、より多くの情報をここで見つけました
https://velog.io/@pearpearb/알고리즘-74-Is-this-a-triangle
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
function isTriangle(a,b,c)
{
[a, b, c] = [a, b, c].sort((x, y) => x-y);
return a+b > c;
}
Reference
この問題について(アルゴリズム74-Is this a三角形?), 我々は、より多くの情報をここで見つけました https://velog.io/@pearpearb/알고리즘-74-Is-this-a-triangleテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol