Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- const x1 = Number(arr[0]);
- const y1 = Number(arr[1]);
- const x2 = Number(arr[2]);
- const y2 = Number(arr[3]);
- function distance(x1, y1, x2, y2) {
- const distH = x1 - x2;
- const distY = y1 - y2;
- return Math.sqrt(distH ** 2 + distY ** 2);
- }
- if (Number.isInteger(distance(x1, y1, 0, 0))) {
- console.log(`{${x1}, ${y1}} to {0, 0} is valid`);
- } else {
- console.log(`{${x1}, ${y1}} to {0, 0} is invalid`);
- }
- if (Number.isInteger(distance(x2, y2, 0, 0))) {
- console.log(`{${x2}, ${y2}} to {0, 0} is valid`);
- } else {
- console.log(`{${x2}, ${y2}} to {0, 0} is invalid`);
- }
- if (Number.isInteger(distance(x1, y1, x2, y2))) {
- console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`);
- } else {
- console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement