β‘
Debounce
Debounceμ΄λ €μ ν¨μ +40pts
Problem
Write a debounce function that delays invoking a function until after a wait period.
Examples
Input:
debounce(fn, 100)Output:
100ms νμ λ§μ§λ§ νΈμΆλ§ μ€νExplanation
μ΄ λ¬Έμ λ **λλ°μ΄μ€(debounce)** ν¨ν΄μ ꡬννμ¬ μ°μλ νΈμΆ μ€ λ§μ§λ§ νΈμΆλ§ μ€ννλ λ°©λ²μ νμ΅ν©λλ€. ## ν΅μ¬ κ°λ : λλ°μ΄μ€ λλ°μ΄μ€λ μ°μλ μ΄λ²€νΈ μ€ λ§μ§λ§ μ΄λ²€νΈλ§ μ²λ¦¬νλ κΈ°λ²μ λλ€. ### μ κ·Ό λ°©λ² ```javascript function debounce(fn, wait) { let timeout; return function(...args) { clearTimeout(timeout); timeout = setTimeout(() => fn.apply(this, args), ...
View detailed explanation βKey Concepts
λλ°μ΄μ€ setTimeout clearTimeout μ΄λ²€νΈ μ΅μ ν
Time: O(1) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.