fm-snippets icon indicating copy to clipboard operation
fm-snippets copied to clipboard

async debounce exercise 10

Open ooddaa opened this issue 1 year ago • 0 comments

Hey!

In the solution this line is

setTimeout(function() { console.log(giveHiSometimes()); }, 4000); // -> 'hi'

whilst in the original course task file it's

setTimeout(function() { console.log(giveHiSometimes()); }, 4000); // -> undefined

Therefore the solution works for the variant from the repo and does not work for the variant in the course task file.

The code below works for the task file variant, but does not work for the solution variant 😂

function debounce(callback, interval) {
  let lastCall; 
  
  return () => {
    const thisCall = new Date().valueOf()
    const cond = !lastCall || thisCall > (lastCall + interval)
    lastCall = thisCall
    if (cond) return callback()
  }
}

What am I missing?

ooddaa avatar Jun 09 '24 15:06 ooddaa