← Back to challenges

Points on Rectangle Bounds

JavaScriptHardmatharrays

Instructions

Given an array of 2D points [x, y], create a function that returns true if those points can be on the bounds of a rectangle, false otherwise.

Examples

onRectangleBounds([[0, 1], [1, 0], [1, 1], [0, 0]]) ➞ true

onRectangleBounds([[0, 1], [1, 0], [1, 1], [0.5, 0.5]]) ➞ false

onRectangleBounds([[0, 1], [10, 0], [10, 1]]) ➞ true

onRectangleBounds([[0, 1]]) ➞ true

Notes

Only rectangles with sides parallel to x-axis and y-axis will be considered.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.