📖 Что делает этот код?
```js
function debounce(fn, ms) {
let timer = null;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), ms);
};
}
function throttle(fn, ms) {
let lastCall = 0;
return function (...args) {
const now = Date.now();
if (now - lastCall >= ms) {
lastCall = now;
fn.apply(this, args);
}
};
}
```
Чем debounce отличается от throttle, когда что использовать.