🚀 Day 4 of My 30 Days of JavaScript Challenge 🧩 Problem: Create Counter II (LeetCode #2665) Write a function createCounter(init) that returns an object with three functions: increment() → increases the current value by 1 and returns it decrement() → decreases the current value by 1 and returns it reset() → resets the value back to init and returns it 💻 Language: JavaScript ❓ Question: https://lnkd.in/eupkr-a3 💡 Solution: https://lnkd.in/eq3BEsn2 🧠 Concepts Used: Closures for maintaining private state across function calls Object methods to encapsulate multiple related actions State management inside functions 📚 Takeaway: This challenge reinforces closures and encapsulation — two powerful ideas that make JavaScript functions behave like real objects with memory and behavior. #Day4 #JavaScript #30DaysOfCode #LeetCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
"Day 4: JavaScript Challenge - Create Counter II"
More Relevant Posts
-
🚀 Day 4 of My 30 Days of JavaScript Journey ✅ Challenge: Create Counter Object (LeetCode #2665) Write a function createCounter(init) that returns an object with three functions: increment() → increases the value by 1 and returns it. decrement() → decreases the value by 1 and returns it. reset() → resets the value to the initial value and returns it. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gKxPxb8Y 💡 Solution: https://lnkd.in/g3jv6Nfi 🧠 Concept Highlighted: This challenge strengthens understanding of closures and object methods in JavaScript. It shows how functions can preserve and modify internal state — a key concept in building dynamic, stateful applications. #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #Closures #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 10 of My 30 Days of JavaScript Challenge 🧩 Problem: Allow One Function Call (LeetCode #2666) Given a function fn, return a new function that ensures fn can only be called once. The first call returns the actual result, and every subsequent call returns undefined. 💻 Language: JavaScript 📖 Problem Link: https://lnkd.in/epnrfahZ 💡 Solution: https://lnkd.in/eGQKWkEk 🧠 Concepts Used Closures to store state (whether function is already called) Function Wrapping Higher-Order Functions 📚 Takeaway This problem is a great example of how closures preserve state between function calls — an essential concept for: Memoization API rate-limiting Event listener control #Day10 #JavaScript #30DaysOfCode #LeetCode #WebDevelopment #CodingChallenge #Closures #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 2 of My 30 Days of JavaScript Journey ✅ Challenge: Counter Function (LeetCode #2620) Create a function createCounter(n) that returns another function. Each time the returned function is called, it should return the current value of n and then increment it by 1 — producing outputs like (n, n+1, n+2, ...). 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gczTUyQ4 💡 Solution: https://lnkd.in/g2VVnv8u 🧠 Concept Highlighted: This problem reinforces the concept of closures — how JavaScript functions can "remember" variables from their outer scope even after the outer function has finished executing. It’s a foundational concept for mastering state management and functional programming in JS. 📘 My Takeaway: A small problem, but a powerful reminder that closures are at the heart of JavaScript. Understanding how functions preserve state paves the way for writing more efficient and modular code. Step by step, the logic becomes clearer! 💪 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #Closures
To view or add a comment, sign in
-
🚀 Day 5 of My 30 Days of JavaScript Challenge 🧩 Problem: Apply Transform Over Each Element in Array (LeetCode #2635) Given an integer array arr and a mapping function fn, return a new array such that: newArray[i] = fn(arr[i], i) Solve this without using the built-in Array.map() method. 💻 Language: JavaScript ❓ Question: https://lnkd.in/eq8qYfpb 💡 Solution: https://lnkd.in/eT5U2kBp 🧠 Concepts Used: Higher-order functions (passing functions as arguments) Loops and callback functions Core idea behind how .map() works internally 📚 Takeaway: By recreating the Array.map() method manually, I learned how callback execution and array transformations work under the hood — a must-know for mastering JavaScript fundamentals. #Day5 #JavaScript #30DaysOfCode #LeetCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 3 of My 30 Days of JavaScript Challenge 🧩 Problem: Implement expect() Function (LeetCode #2704) Write a function expect that helps developers test their code. It takes a value val and returns an object with two methods: toBe(val) → returns true if both values are strictly equal (===), else throws "Not Equal" notToBe(val) → returns true if both values are not strictly equal (!==), else throws "Equal" 💻 Language: JavaScript ❓ Question: https://lnkd.in/eJcRKeme 💡 Solution: https://lnkd.in/eZY9mYHN 🧠 Concepts Used: Higher-order functions (function returning object with functions) Error handling using throw new Error() Strict equality (===) in JavaScript 📚 Takeaway: This exercise reinforces function design, object methods, and error handling — the foundation for building custom testing utilities and debugging tools in JavaScript. #Day3 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 10 of My 30 Days of JavaScript Journey ✅ Challenge: Allow One Function Call (LeetCode #2666) Create a function once(fn) that ensures a given function can only be executed once. The first call should execute and return the result of fn, while all subsequent calls should return undefined. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gpX3MkFD 💡 Solution: https://lnkd.in/gAYsYP6d 🧠 Concept Highlighted: This problem focuses on closures and function state management in JavaScript. By storing state within a closure, we can control how many times a function executes — a powerful concept for optimizing performance and preventing redundant calls. #Day10 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #Closures #LearningEveryday #ProblemSolving #ES6
To view or add a comment, sign in
-
🚀 Day 11 of My 30 Days of JavaScript Journey ✅ Challenge: Memoize (LeetCode #2623) The task was to create a memoize(fn) function that caches results so that repeated calls with the same inputs return instantly from cache — without re-executing the original function. This helps improve performance when dealing with expensive computations like fibonacci or factorial, and even simple operations like sum when called repeatedly. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gnHmbPih 💡 Solution: https://lnkd.in/gGJZjYY9 🧠 Concept Highlighted: Memoization is a powerful optimization technique that uses caching to avoid repeating calculations. It strengthens understanding of closures, function arguments handling, and performance-oriented JavaScript. #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #Memoization #PerformanceOptimization #LearningEveryday #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 1 of My 30 Days of JavaScript Challenge 🧩 Problem: Create Hello World Function (LeetCode #2667) Write a function createHelloWorld that returns a new function which always returns "Hello World", no matter what arguments are passed. 💻 Language: JavaScript ❓ Question: https://lnkd.in/eVgQ9W87 💡Solution:https://lnkd.in/ed7AXEYr 🧠 Concept Used: JavaScript closures and higher-order functions Demonstrates how a function can return another function 📚 Takeaway: A simple yet powerful reminder that understanding function behavior and scope is key in JavaScript. Every small step builds stronger fundamentals! #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 6 of My 30 Days of JavaScript Challenge 🧩 Problem: Filter Elements from Array (LeetCode #2634) Given an integer array arr and a filtering function fn, return a new array filteredArr that only includes elements where fn(arr[i], i) returns a truthy value. Solve this without using the built-in Array.filter() method. 💻 Language: JavaScript ❓ Question: https://lnkd.in/eSGpgXcM 💡 Solution: https://lnkd.in/ekA6y-u3 🧠 Concepts Used: Higher-order functions and callbacks Conditional checks for truthy/falsy values Understanding Boolean(value) behavior in JavaScript 📚 Takeaway: Rebuilding filter() from scratch deepens understanding of conditional logic, iteration, and truthy/falsy evaluation — all essential for functional programming in JavaScript. #Day6 #JavaScript #30DaysOfCode #LeetCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 7 of My 30 Days of JavaScript Journey ✅ Challenge: Array Reduce Transformation (LeetCode #2626) Write a function reduce(nums, fn, init) that processes each element of the array using the given reducer function fn, starting from an initial value init. This function should accumulate results sequentially and return the final value — implemented without using the built-in Array.reduce() method. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gxsp26cz 💡 Solution: https://lnkd.in/giZj_hYw 🧠 Concept Highlighted: This problem deepened my understanding of accumulator functions, data aggregation, and sequential computation in JavaScript. It helped me explore how the powerful reduce() method works behind the scenes — a key tool for transforming and summarizing data efficiently. #Day7 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #ProblemSolving #FunctionalProgramming
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