forked from epoch/javascript-basics-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangles.js
More file actions
27 lines (18 loc) · 766 Bytes
/
triangles.js
File metadata and controls
27 lines (18 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
let a = 2
let b = 2
let c = 4
function isNegative(element) { element < 0 }
function isTriangle(a, b, c) {
let sides = [a,b,c]
if (sides.some(isNegative)) {
return false
} else {
return ((a + b > c) && (a + c > b) && (b + c > a)) ? true : false
}
}
module.exports = {isTriangle: isTriangle}
console.log(isTriangle(1, 1, 1))
console.log(isTriangle(4, 5, 6))
console.log(isTriangle(-3,3, 9))
// Write a function called isTriangle which takes an input of three non-negative numbers. It should return true if the three numbers could form the side lengths of a triangle and false otherwise.
// The sum of two sides of a triangle must be greater than the third side. If this is true for all three combinations, then you will have a valid triangle.