Quick actions

cmd+k|ctrl+k

Navigation

Languages

missing square coord

Snippet info

Language

JavaScript

Visibility

public

Author

soham57

Created

2024-04-11T13:50:16.731856Z

Updated

2024-04-11T13:50:16.731856Z

function findMissingCoordinate(squareCoords) {
  // Initialize variables to store x and y coordinates separately
  let xCoords = [];
  let yCoords = [];

  // Extract x and y coordinates from the input array
  for (let i = 0; i < squareCoords.length; i++) {
    xCoords.push(squareCoords[i][0]);
    yCoords.push(squareCoords[i][1]);
  }

  // Find the missing x coordinate
  let missingX = xCoords.reduce((acc, cur) => acc ^ cur, 0);

  // Find the missing y coordinate
  let missingY = yCoords.reduce((acc, cur) => acc ^ cur, 0);

  return [missingX, missingY];
}

// Example usage
let square1 = [[1, 1], [1, 3], [3, 1]]; // Missing point: [3, 3]
let square2 = [[0, 0], [0, 1], [1, 0]]; // Missing point: [1, 1]

console.log(findMissingCoordinate(square1)); // Output: [3, 3]
console.log(findMissingCoordinate(square2)); // Output: [1, 1]
INFO