Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pointsValidation(arr) {
- let x1 = arr[0];
- let y1 = arr[1];
- let x2 = arr[2];
- let y2 = arr[3];
- let checkFirst = firstPoint(arr);
- let checkSecond = secondPoint(arr);
- let checkThird = thirdPoint(arr);
- function firstPoint() {
- return Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2));
- }
- function secondPoint() {
- return Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2));
- }
- function thirdPoint() {
- return Math.sqrt(Math.pow(Math.abs(x2 - x1), 2) + Math.pow(Math.abs(y2 - y1), 2));
- }
- console.log(`{${x1}, ${y1}} to {0, 0} is ${checkFirst === Math.trunc(checkFirst) ? 'valid' : 'invalid'}`);
- console.log(`{${x2}, ${y2}} to {0, 0} is ${checkSecond === Math.trunc(checkSecond) ? 'valid' : 'invalid'}`);
- console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is ${checkThird === Math.trunc(checkThird) ? 'valid' : 'invalid'}`);
- }
Add Comment
Please, Sign In to add comment