code: function throttle(func, wait) {
          let timeout = null;
          let previous = 0;
  
          function later() {
            previous = new Date().getTime();
            $interval.cancel(timeout);
            timeout = null;
            return func.call();
          }
  
          function throttled() {
            const now = new Date().getTime();
            const remaining = wait - (now - previous);
            if (remaining <= 0) {
              $interval.cancel(timeout);
              timeout = null;
              previous = now;
              func.call();
            } else if (!timeout) {
              timeout = $interval(later, remaining, 1);
            }
          }
  
          return throttled;
        }
docs: The optional THROTTLE_MILLISECONDS configuration value specifies a minimum time that should elapse between each call to the handler. N.b. the first call the handler will be run immediately, and the final call will always result in the handler being called after the `wait` period elapses. A slimmed down version of underscore's implementation.