Read here. Code on desktop. The coding workspace opens on screens 1024px and wider.
JavaScript interview question
Reading Order
easy15 min
Order positioned items from top to bottom and, within each row, from left to right.
Requirements
Implement readingOrder(elements). Every item has finite numeric x and y coordinates, representing its top-left position in a canvas where y increases downward and x increases rightward. Additional item properties must be preserved.
Sort by y ascending first. Items with exactly the same y are sorted by x ascending. Items with equal x and y keep their original relative order.
Return a new array containing the original item references. Do not mutate the input array or its objects. Support empty arrays and negative or fractional coordinates.
This exercise uses exact coordinate rows. Do not group nearby y values, inspect width/height, handle overlapping bounding boxes, or use locale/right-to-left ordering. No canvas rendering, HTML, or CSS is required.