Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isValidDistance(points) {
- for (let i = 0; i < 3; i++) {
- let x1, y1, x2, y2;
- if (i === 0) {
- x1 = points[0];
- y1 = points[1];
- x2 = 0;
- y2 = 0;
- } else if (i === 1) {
- x1 = points[2];
- y1 = points[3];
- x2 = 0;
- y2 = 0;
- } else {
- x1 = points[0];
- y1 = points[1];
- x2 = points[2];
- y2 = points[3];
- }
- let distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
- if (distance % 1 === 0) {
- console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`);
- } else {
- console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
- }
- }
- }
- isValidDistance([3, 0, 0, 4]);
- isValidDistance([2, 1, 1, 1]);
Advertisement
Add Comment
Please, Sign In to add comment