Guest User

Untitled

a guest
Mar 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. // return a number with commas
  2. function numberWithCommas(x) {
  3. return x = x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  4. }
  5.  
  6. // debounce function
  7. function debounce(func, wait = 20, immediate = true) {
  8. var timeout;
  9. return function() {
  10. var context = this, args = arguments;
  11. var later = function() {
  12. timeout = null;
  13. if (!immediate) func.apply(context, args);
  14. };
  15. var callNow = immediate && !timeout;
  16. clearTimeout(timeout);
  17. timeout = setTimeout(later, wait);
  18. if (callNow) func.apply(context, args);
  19. };
  20. }
Add Comment
Please, Sign In to add comment