Problem Statement
Different use cases require different debounce behaviors. Implement a flexible debounce function that supports configuration for both leading and trailing edge execution.
Requirements
Implement a debounce(func, wait, options) function where options include:
leading(boolean, default: false) - invoke on the leading edgetrailing(boolean, default: true) - invoke on the trailing edge
Example Usage
Edge Cases to Consider
- What happens when both leading and trailing are false?
- What if the function is called exactly once?
- How do you handle rapid calls that span multiple wait periods?
Follow-up Questions
- How would Lodash's debounce handle this scenario?
- What are the tradeoffs of this API design?