What is an efficient way to implement a debounce function in JavaScript to control how often a function is executed, particularly for events like scrolling or resizing?
I initially wrote a debounce function that wraps another function and delays its execution using