Skip to content

Conversation

@codomposer
Copy link
Contributor

Add Throttle Function Interview Question Example

Overview

This PR adds a comprehensive throttle function example to the JavaScript interview questions repository, providing a valuable companion piece to the existing debounce function example.

Changes Made

  • Added throttle-function/ directory under coding-exercise/
  • Created throttle.js - Complete implementation with multiple approaches, detailed comments, and working demonstration
  • Created README.md - Comprehensive documentation covering:
    • Challenge description and use cases
    • Implementation approaches (leading edge, leading + trailing)
    • Throttle vs Debounce comparison table
    • Interview tips and common questions
    • Common pitfalls and solutions
    • Advanced variations and testing considerations

Why This Matters

  • Interview Preparation: Throttle functions are a common JavaScript interview topic, often asked alongside debounce
  • Performance Optimization: Essential concept for handling high-frequency events (scroll, resize, mouse move)
  • Code Quality: Demonstrates advanced JavaScript concepts like closures, higher-order functions, and timing management
  • Real-World Relevance: Covers practical scenarios like API rate limiting, scroll performance, and game development

Key Features

  • ✅ Multiple implementation strategies
  • ✅ Detailed inline documentation and JSDoc
  • ✅ Working code examples with console output
  • ✅ Comprehensive comparison with debounce
  • ✅ Interview-ready explanations and tips
  • ✅ Performance benefits and use case examples

Testing

The code has been tested and produces expected output, demonstrating throttling behavior by reducing function calls from 8 potential executions to 3 actual executions (62.5% reduction).

Related

This complements the existing debounce-function/ example, providing developers with both essential performance optimization patterns for JavaScript interviews.

@codomposer
Copy link
Contributor Author

@sudheerj I think current failing workflow is not related with my new code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant