Implement a Throttle Function That Limits Execution to Once Per Time Window

Implement throttle(fn, limit) which ensures fn is called at most once per limit milliseconds regardless of how many times the throttled function is invoked. Unlike debounce, throttle guarantees periodic execution during sustained activity. Implement it using both timestamp-based and timer-based approaches. Common use cases include scroll event handlers, window resize listeners, and rate-limited button clicks.

Examples
Input: []
Output:
Hints

Implement a Throttle Function That Limits Execution to Once Per Time Window

Implement throttle(fn, limit) which ensures fn is called at most once per limit milliseconds regardless of how many times the throttled function is invoked. Unlike debounce, throttle guarantees periodic execution during sustained activity. Implement it using both timestamp-based and timer-based approaches. Common use cases include scroll event handlers, window resize listeners, and rate-limited button clicks.