| 8 | 8 | * @param {number} y |
| 9 | 9 | * @returns {number} |
| 10 | 10 | */ |
| 11 | | export const score = (x, y) => { |
| 12 | | throw new Error('Remove this line and implement the function'); |
| 11 | const score = (x, y) => { |
| 12 | // Edge Case: Handle invalid inputs (non-numbers) |
| 13 | if (typeof x !== 'number' || typeof y !== 'number' || isNaN(x) || isNaN(y)) { |
| 14 | return 0; |
| 15 | } |
| 16 | |
| 17 | // Calculate the squared distance from center (to avoid floating point operations) |
| 18 | const distanceSquared = x * x + y * y; |
| 19 | |
| 20 | // Edge Case: Points exactly on circle boundaries (using <= to include boundaries) |
| 21 | if (distanceSquared <= 1) { |
| 22 | return 10; |
| 23 | } else if (distanceSquared <= 25) { |
| 24 | return 5; |
| 25 | } else if (distanceSquared <= 100) { |
| 26 | return 1; |
| 27 | } else { |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | // Edge Case: Negative coordinates (handled naturally by squaring) |
| 32 | // Edge Case: Origin point (0,0) (handled as distanceSquared = 0, which is <= 1) |
| 33 | // Edge Case: Points far outside the target (handled by final else clause) |
| 34 | // Edge Case: Floating point precision issues (minimized by using squared distances) |
| 13 | 35 | }; |
| 36 | |
| 37 | // Handled Edge Cases: invalid inputs, points exactly on circle boundaries, negative coordinates, origin point, points far outside the target, floating point precision issues |
| 38 | |
| 39 | module.exports = { score }; |