Domanda di colloquio di Google

How do you make a function that only calls input function f every 50 milliseconds?

Risposte di colloquio

Anonimo

17 mar 2019

Actually whats being asked is Debounce. Its a pretty common concept for Frontend function debounce(func, time) { let timeout; return () => { const args = arguments; const invokeLater = () => { timeout = null; func.apply(null, args); }; clearTimeout(timeout); timeout = setTimeout[invokeLater, time); }; }

7

Anonimo

12 ott 2018

why not this: function call50ms(f) { setInterval[f, 50) }

3

Anonimo

5 nov 2017

function call50ms(f){ setInterval[f.bind(null, ...Array.from(arguments).slice(1)), 50); }

1