⚑

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.