(decorator) suspends calls to funtil there’s sseconds of inactivity (no further calls), then invokes the lastfunction call (previous calls are ignored).
// 📁 debounce.js// ⭐️ decorator: "debounce"// (suspends 'f' for 's' seconds)functiondebounce(f, s) {// logconsole.log(`'${f.name}' has been debounced by ${s} seconds.`)// ⭐️ timer idlet timer;// wrapperreturnfunctionwrapper(...args) {// ⭐️ clear old timer (if it exits) clearTimeout(timer);// ⭐️ set new timer (in s seconds) timer =setTimeout( () =>f.apply(this, args), s *1000 ); }}// exportmodule.exports= { debounce };