Skip to content

Instantly share code, notes, and snippets.

@coder0107git
Created February 1, 2023 18:27
Show Gist options
  • Save coder0107git/4fefe9ef72941f0927d0c6987ddc1065 to your computer and use it in GitHub Desktop.
Save coder0107git/4fefe9ef72941f0927d0c6987ddc1065 to your computer and use it in GitHub Desktop.
Check if coordinates are a solution to simple systems in javascript
// Coordinates to check system against
const coordinates = [
[-3, 0],
[5, 1],
[-4, 3],
[2, -6],
];
// System without solving for Y
function system1(x, y) {
return (3 * x) + (2 * y) === -6;
}
// System solved for Y.
function system2(x, y) {
return y == (-3 * x) - 9;
}
function systemTest(x, y) {
return [
[x, y], // Print coordinate pair currently testing
system1(x, y) && system2(x, y) // Check coordinate pair
];
}
document.write(JSON.stringify(
coordinates.map(value => systemTest(...value)) // Test each coordinate
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment