A layout debugger highlights where two elements overlap. Each element's box is like the result of getBoundingClientRect(): { x, y, width, height }, where (x, y) is the top-left corner and y grows downward.
Write overlapArea(a, b) that returns the area of the region covered by both boxes. Boxes that only touch along an edge or a corner overlap with area 0.
Input: a = {"x":0,"y":0,"width":100,"height":50}, b = {"x":60,"y":20,"width":80,"height":60} Output: 1200
The shared region runs from x = 60 to 100 and from y = 20 to 50: 40 × 30 = 1200.
Input: a = {"x":0,"y":0,"width":10,"height":10}, b = {"x":10,"y":0,"width":5,"height":5} Output: 0
The boxes only touch along the line x = 10.
-10^4 <= x, y <= 10^40 <= width, height <= 10^4Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #661 Overlap Area of Two Boxes. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.