[Fully Explained] 1 Line Code with Concept Explanation 🔥| Closures | Arrow Functions | Currying
Intuition \uD83D\uDCA1\n Describe your first thoughts on how to solve this problem. \nThe goal is simple: start at n and return n + 1 every time the function is
# Intuition \uD83D\uDCA1\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is simple: start at n and return n + 1 every time the function is called. Easy peasy, right?\n\n# Approach \uD83E\uDD14\n<!-- Describe your approach to solving the problem. -->\nAfter a quick brainstorm, it\'s clear that we need to create a function that can remember its previous state. We\'ll need to initialize the function with an input value of n, and then use a *closure* to keep track of a running count. Each time the function is called, we\'ll increase the count by 1 and return the current count value plus n. With a bit of ES6 syntax, we can create this counter function in just one line of code!\n\n# Concepts \uD83D\uDCDA\n\n### What is a Closure? \n\nAh, closures. They may sound like something you would find in a haunted house, but they\'re actually a fundamental concept in programming. In short, a closure is a function that has access to variables in its outer scope, even after that scope has closed. This means that a closure can "remember" values from the parent function or the global scope, even if those values are no longer in memory. Closures are created whenever a function is defined inside another function and that inner function is returned or passed around as an argument.\n\n### What is an Arrow Function?\n\nArrow functions are a way to write functions in JavaScript that are shorter and easier to read. They use a special arrow symbol (=>) to show that they\'re a function. They work just like regular functions, but there are a few important differences.\n\n- The first difference is that arrow functions don\'t have their own "this" value. This means that they use the "this" value from the function that contains them.\n\n- The second difference is that you can\'t create new objects with arrow functions. So, if you need to make a lot of objects that are all the same, you\'ll need to use a regular function instead.\n\n- Finally, arrow functions don\'t have a name. This means that you can\'t refer to them by name, like you can with regular functions.\n\nArrow functions are really useful when you want to write short, simple functions. They\'re also great for working with arrays in JavaScript, which is something you\'ll learn more about as you continue to learn about programming.\n\n### What is Currying? \n\nCurrying is a programming technique where you break down a function that takes multiple arguments into a series of smaller functions, each of which takes only one argument.\n\n# Complexity Analysis \uD83D\uDC7E\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of our counter function is constant, or O(1). Each time the function is called, we\'re simply incrementing a counter and returning its value, which takes a constant amount of time regardless of the size of n.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity of our counter function is also constant, or O(1). We\'re not storing any additional data beyond the input value n and the internal counter, both of which take up a constant amount of memory.\n\n# Code\n```\n/**\n * @param {number} n\n * @return {Function} counter\n */\n  \nvar createCounter = n => () => n++;  \n\n/** \n * const counter = createCounter(10)\n * counter() // 10\n * counter() // 11\n * counter() // 12\n */\n```
['JavaScript']