β‘
Throttle
Throttleμ΄λ €μ ν¨μ +40pts
Problem
Write a throttle function that limits how often a function can be called.
Examples
Input:
throttle(fn, 100)Output:
100msλ§λ€ μ΅λ 1λ²λ§ μ€νExplanation
μ΄ λ¬Έμ λ **μ€λ‘ν(throttle)** ν¨ν΄μ ꡬννμ¬ ν¨μ μ€ν λΉλλ₯Ό μ ννλ λ°©λ²μ νμ΅ν©λλ€. ## ν΅μ¬ κ°λ : μ€λ‘ν μ€λ‘νμ μΌμ μκ° λμ μ΅λ ν λ²λ§ ν¨μκ° μ€νλλλ‘ μ νν©λλ€. ### μ κ·Ό λ°©λ² ```javascript function throttle(fn, limit) { let lastCall = 0; return function(...args) { const now = Date.now(); if (now - lastCall >= limit) { lastCall = n...
View detailed explanation βKey Concepts
μ€λ‘ν Date.now μ€ν λΉλ μ ν μ±λ₯ μ΅μ ν
Time: O(1) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.