Skip to content

Instantly share code, notes, and snippets.

@jimmycuadra
Created September 13, 2012 00:55
Show Gist options
  • Save jimmycuadra/3711084 to your computer and use it in GitHub Desktop.
Save jimmycuadra/3711084 to your computer and use it in GitHub Desktop.
Debounce question
/*
Fill in the body of the `debounce` function, such that running
the following code will output "fn was called with 10!" only once.
*/
(function () {
var debounce, fn, i;
debounce = function (func, wait) {
// ...
};
fn = function (n) {
console.log("fn was called with " + n + "!");
};
fn = debounce(fn, 10);
for (i = 0; i < 10; i++) {
setTimeout(function () {
fn(i);
}, 5);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment