Skip to content

Commit 830af7a

Browse files
authored
Create 1037-valid-boomerang.js
1 parent 2996923 commit 830af7a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

1037-valid-boomerang.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[][]} points
3+
* @return {boolean}
4+
*/
5+
const isBoomerang = function(points) {
6+
if(angle(points[0], points[1], points[2]) &&
7+
angle(points[1], points[2], points[0]) &&
8+
angle(points[1], points[0], points[2]) ) return false
9+
return true
10+
};
11+
12+
// distinct or in a line
13+
function angle(p1, p2, p3) {
14+
if((p1[0] === p2[0] && p1[1] === p2[1]) ||
15+
(p2[0] === p3[0] && p2[1] === p3[1]) ||
16+
(p1[0] === p3[0] && p1[1] === p3[1]) ) return true
17+
18+
return collinear(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1])
19+
}
20+
function collinear(x1, y1, x2, y2, x3, y3) {
21+
return (y3 - y2) * (x2 - x1) === (y2 - y1) * (x3 - x2)
22+
}

0 commit comments

Comments
 (0)