Solved #2666 LeetCode challenge: once function with closures

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

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories