Rectangle Area with Optional Height
Optional properties can drive different behaviors. If height is provided, compute width * height; otherwise treat the value as a square and compute width * width.
Your Task
- Complete the function area(rect: { width: number; height?: number }): number.
- If height exists, return rect.width * rect.height.
- Otherwise, return rect.width * rect.width.
Examples
- area({ width: 3 }) → 9
- area({ width: 3, height: 4 }) → 12