Created
February 1, 2023 18:27
-
-
Save coder0107git/4fefe9ef72941f0927d0c6987ddc1065 to your computer and use it in GitHub Desktop.
Check if coordinates are a solution to simple systems in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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