missing square coord

Run Settings
LanguageJavaScript
Language Version
Run Command
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]
Editor Settings
Theme
Key bindings
Full width
Lines