Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function distance(array) {
- let result = checkDistance();
- console.log(result);
- function checkDistance() {
- let x1 = array.shift();
- let y1 = array.shift();
- let x2 = array.shift();
- let y2 = array.shift();
- let toPrint = '';
- let xPointToZero = Math.sqrt(Math.pow((x1 - 0), 2) + Math.pow((y1 - 0), 2));
- let yPointToZero = Math.sqrt(Math.pow((y1 - 0), 2) + Math.pow((y2 - 0), 2));
- let distanceBetweenPoints = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
- if (Number.isInteger(xPointToZero)) {
- toPrint += `{${x1}, ${y1}} to {0, 0} is valid\n`;
- } else {
- toPrint += `{${x1}, ${y1}} to {0, 0} is invalid\n`;
- }
- if (Number.isInteger(yPointToZero)) {
- toPrint += `{${x2}, ${y2}} to {0, 0} is valid\n`;
- } else {
- toPrint += `{${x2}, ${y2}} to {0, 0} is invalid\n`;
- }
- if (Number.isInteger(distanceBetweenPoints)) {
- toPrint += `{${x1}, ${y1}} to {${x2}, ${y2}} is valid\n`;
- } else {
- toPrint += `{${x1}, ${y1}} to {${x2}, ${y2}} is invalid\n`;
- }
- return toPrint;
- }
- }
- distance([3, 0, 8, 0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement