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
How to memoize a function with JavaScript and LeetCode
More Relevant Posts
-
🚀 Day 81 of #100DaysOfCode Today I learned how to create object literals in JavaScript. An object literal lets you store related data as key-value pairs inside curly braces. For example: const car = { brand: "Toyota", year: 2020, color: "red" }; This way, you can easily organize, access, and update complex data as one unit. Object literals are foundational for structuring real-world information in your programs. #JavaScript #ObjectLiterals #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
Day 26 – Understanding Scope, Closure & Higher-Order Functions in JavaScript Today I learned about three powerful concepts in JavaScript: Scope, Closure, and Higher-Order Functions. These concepts helped me understand how data access and function behavior actually work behind the scenes. The lecture was deeply insightful and covered ideas that are rarely explained this clearly. Thanks to Rohit Negi for the guidance. #coderArmy #JavaScript #WebDevelopment #Frontend #LearningInPublic #Programming #tech #coding #GrowthJourney
To view or add a comment, sign in
-
-
Day 15 of #30DaysOfJavaScript on LeetCode Today's Challenge: 2725 — Interval Cancellation This problem focused on mastering repeated asynchronous execution in JavaScript — specifically, how to repeatedly run a function using setInterval() and stop it with clearInterval(). Here’s my solution 👇 var cancellable = function(fn, args, t) { fn(...args); let timer = setInterval(() => fn(...args), t); let cancelFn = () => clearInterval(timer); return cancelFn; }; This exercise helped me understand how interval-based scheduling works and how to control execution flow by canceling ongoing intervals a common pattern in real-world applications like periodic data fetching or live updates. Try it out here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #AsyncAwait #Promises #30DaysOfCode #Programming #Developers #LearningJourney
To view or add a comment, sign in
-
-
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 34 | Mastering Operators & Conditionals in JavaScript Today’s session (Lec-41) was packed with logic and power! 🔥 I explored how JavaScript makes decisions and performs calculations — the true backbone of programming. 💡 Key Highlights: ● Arithmetic, Comparison, Logical & Bitwise Operators ● Short-circuit evaluation & ternary conditions ● if, else if, and switch statements in real-world logic These concepts make code think — transforming simple scripts into intelligent, responsive programs. 🙏 Thanks to @Love for simplifying complex logic beautifully! ✅ Day 35 complete — 46 more to go 🚀 🔗 GitHub Repo: https://lnkd.in/dtdU9-zZ #JavaScript #WebDevelopment #Frontend #CodingJourney #LearnWithMe #Programming #LoveForCoding ❤️
To view or add a comment, sign in
-
Day 9 of #30DaysOfJavaScript on LeetCode Today's challenge: 2703 — Return Length of Arguments Passed The task was to write a function that returns the number of arguments passed to it — a simple yet elegant problem to explore rest parameters in JavaScript. Here’s my solution 👇 var argumentsLength = function(...args) { return args.length; }; It’s a short problem but a great reminder that even small concepts like this are essential for mastering function flexibility in JavaScript! Try it out here : https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #Functions #RestParameters #Programming
To view or add a comment, sign in
-
-
Day 7 of #30DaysOfJavaScript on LeetCode Today's challenge: 2626 — Array Reduce Transformation The task was to implement a custom reduce() function that applies a reducer function (fn) on each element of an array, accumulating the result — just like the built-in Array.reduce() method, but without using it. Here’s my solution 👇 var reduce = function(nums, fn, init) { let ans = init; for (let i = 0; i < nums.length; i++) { ans = fn(ans, nums[i]); } return ans; }; This challenge helped me understand how accumulators work and how values are carried forward during iteration. It deepened my appreciation for how methods like reduce() process arrays step by step turning a list of elements into a single meaningful result. If you’d like to give it a shot, check it out here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #Functions #Callbacks #Arrays #Reduce #Programming
To view or add a comment, sign in
-
-
🔁 JavaScript Loops — They Literally Put Me in a Loop 😅 Started learning loops today, and wow… they’re the real deal when it comes to writing less code that does more! ⚙️ Loops basically say: > “Why write it ten times when I can do it for you?” 😎 Here’s what I explored 👇 🔹 for loop — when you know exactly how many times to run 🔹 while loop — keeps going as long as the condition’s true 😆 🔹 do...while — runs at least once, no matter what 🔹 for...of / for...in — the cleanest way to loop through arrays and objects It’s crazy how something so simple can automate so much logic 🔄 Feeling one step closer to thinking like a developer now 💪 Next stop → Functions, where the real magic begins! ✨ #JavaScript #WebDevelopment #Frontend #CodingJourney #Loops #Programming #LearningInPublic #DeveloperLife #CleanCode #100DaysOfCode
To view or add a comment, sign in
-
-
Day 3 – JavaScript Loops Practice In this task, I practiced different types of JavaScript loops — for, while, do...while, and for...of — to understand how iteration works in programming. I applied loops to solve small problems like counting numbers, iterating over arrays, and displaying patterns in the console. This practice improved my logic-building skills, debugging techniques, and understanding of flow control in JavaScript. Key Learning Areas: Difference between for, while, and do...while loops Using loops with arrays and objects Avoiding infinite loops and understanding loop conditions Real-time testing using console.log() #JavaScript #WebDevelopment #FrontendLearning #CodingChallenge #Loops #CodingJourney #WomenInTech #100DaysOfCode
To view or add a comment, sign in
Explore related topics
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