Day 10 of #30DaysOfJavaScript on LeetCode Today's Challenge: 2666 — Allow One Function Call Today’s problem was all about controlling function execution — ensuring that a given function runs only once, no matter how many times it’s called afterward. Here’s my solution 👇 var once = function(fn) { let called = false; return function (...args) { if (!called) { called = true; return fn(...args); } }; }; This challenge reinforces the importance of closures in JavaScript — allowing us to preserve state (called) between function invocations. It’s a simple yet powerful example of how closures give us fine-grained control over function behavior. Try it out here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #Closures #Functions #Programming #Developers #Learning
Solved #2666 LeetCode challenge: once function with closures
More Relevant Posts
-
Day 14 of #30DaysOfJavaScript on LeetCode Today's Challenge: 2715 — Timeout Cancellation This problem focused on controlling asynchronous behavior — specifically, learning how to cancel a scheduled function call using setTimeout() and clearTimeout(). Here’s my solution 👇 var cancellable = function(fn, args, t) { let time = setTimeout(() => { fn(...args) }, t) return function() { clearTimeout(time) } } The challenge helped me understand how JavaScript manages timers and how we can cancel pending asynchronous tasks before they execute. Try it out here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #AsyncAwait #Promises #30DaysOfCode #Developers #Programming #LearningJourney
To view or add a comment, sign in
-
-
Unleash the Potential of Array Methods!** Stop writing verbose loops! JavaScript Array methods like `map`, `filter`, and `reduce` are your secret weapons. Write cleaner, more readable, & more performant code. They're not just shorter; they're a whole new level of elegance. What's one Array method that changed the way YOU code? Share your experiences! 👇 #javascript #arrays #codingtips #webdev #programming
To view or add a comment, sign in
-
Day 16 of #30DaysOfJavaScript on LeetCode Today's Challenge: 2637 — Promise Time Limit Today’s challenge focused on controlling asynchronous execution using timeouts. The goal was to wrap any async function with a time limit — if the function doesn't finish in time, it should automatically reject with "Time Limit Exceeded". Here’s my solution: var timeLimit = function(fn, t) { return async function(...args) { const timeOutPromise = new Promise((_, reject) => setTimeout(() => reject("Time Limit Exceeded"), t) ) return Promise.race([fn(...args), timeOutPromise]) } } Try it out here: https://lnkd.in/g6WC5mu7 This exercise helped me understand how to combine Promise.race() with timeouts to enforce execution limits #JavaScript #LeetCode #CodingChallenge #AsyncAwait #Promises #30DaysOfCode #Programming #Developers #LearningJourney
To view or add a comment, sign in
-
-
Just published a beginner-friendly guide to understanding function binding in JavaScript! If you've ever wondered why `this` becomes undefined in callbacks, this article breaks it down with simple examples. Perfect for developers learning JavaScript or anyone who needs a refresher on bind() 💻 https://lnkd.in/dmAU3Rhc #JavaScript #WebDevelopment #Programming #Coding
To view or add a comment, sign in
-
🚀 JavaScript Closures — A Little Magic Trick! Imagine… a function that can remember its past values, even after it has finished running! 😲 That’s the magic of closures. In this 3-frame short video, you’ll see: ✨ What a closure is ✨ How an inner function can access outer variables ✨ Why we use closures #JavaScript #CodingMagic #WebDev #Closures #TechFun #Programming #DeveloperLife
To view or add a comment, sign in
-
Optimizing Network Hops with Jump Game II Greedy Approach in JavaScript LeetCode: 45 #JavaScript #DSA #Algorithms #LeetCode #CodingInterview #GreedyAlgorithm #ProblemSolving #DataStructures #Programming #JumpGame #NetworkOptimization #AlgorithmExplained #TechConcepts #LearnByAnalogy
To view or add a comment, sign in
-
🚀 Final chapter of my LINQ series is out! After exploring IEnumerable, yield return, and unit testing, it’s time to put everything together by building our own LINQ methods from scratch. In this article, I share how I used this project to teach my team that LINQ isn’t “magic”, it’s just clean, powerful C# code. We implement .Where() and .Any() step by step, using everything we’ve learned so far. 👉 Read here: https://lnkd.in/dSS6FHq9 #dotnet #csharp #linq #learning #programming #developers #teamlead
To view or add a comment, sign in
-
-
Turning logic into code Built a JavaScript function to remove adjacent odd numbers from an array — a simple yet powerful reminder that clear logic creates clean results. #JavaScript #Programming #WebDevelopment #ProblemSolving
To view or add a comment, sign in
-
-
Day 11 of #30DaysOfJavaScript on LeetCode Today's Challenge: 2623 — Memoize Today’s problem focused on performance optimization using memoization — a powerful technique to cache the results of expensive function calls and return the cached result when the same inputs occur again. Here’s my solution 👇 function memoize(fn) { const cache = {}; return function(...args) { const key = JSON.stringify(args); if (key in cache) { return cache[key]; } const result = fn(...args); cache[key] = result; return result; } } This challenge highlights how closures and object caching work together to optimize performance — especially useful for recursive functions like Fibonacci or factorial. By storing computed results, we avoid redundant calculations, making our functions significantly faster! Try it out here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #Memoization #Closures #Optimization #Programming #Developers #Learning
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development