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
Implementing custom reduce() function on LeetCode
More Relevant Posts
-
Day 6 of #30DaysOfJavaScript on LeetCode Today's challenge: 2634 — Filter Elements from Array The task was to implement a custom filter function that returns a new array containing only the elements that satisfy a given condition — similar to the built-in Array.filter() method, but without using it. Here’s my solution 👇 var filter = function(arr, fn) { let ans = []; for (let i = 0; i < arr.length; i++) { if (fn(arr[i], i)) ans.push(arr[i]); } return ans; }; This challenge was a great way to understand how callback functions and conditional logic work together in JavaScript — it really helps appreciate how built-in methods like filter() operate under the hood! If you’d like to try it out, check it here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #Functions #Callbacks #Arrays #Programming #Filter
To view or add a comment, sign in
-
-
Every JavaScript developer has hit that confusing moment when var starts acting like it has a mind of its own 😅 I still remember spending hours debugging a scope issue… only to find out that var is function-scoped, while let and const are block-scoped. That’s exactly what we break down in our new Instagram video a quick visual guide to mastering var, let, and const, so you’ll never get caught off guard again. 📹 Check out the full video on our Instagram-> link in the comments 👇 #JavaScript #WebDevelopment #CodingTips #LearnToCode #FrontendDevelopment #Programming #TechEducation
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 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 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 8 of #30DaysOfJavaScript on LeetCode Today's challenge: 2629 — Function Composition The task was to implement a function that takes an array of functions [f1, f2, f3, ..., fn] and returns a new function that represents their composition. In simple terms, the composed function should apply all the given functions from right to left, just like: f(g(h(x))) Here’s my solution 👇 var compose = function(functions) { return function(x) { let res = x; for (let i = functions.length - 1; i >= 0; i--) { res = functions[i](res); } return res; } }; This challenge gave me a deeper understanding of how function chaining and composition work in JavaScript — building complex logic from smaller, reusable functions. It’s a beautiful example of how functional programming principles simplify problem-solving! Try it out here : https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #Functions #Callbacks #Programming #Composition
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
-
If you are still struggling to understand some JavaScript trick concept of Deep and Shallow clone join me as I explore and break down how to deep and shallow clone and also how to apply them with confidence Let's discuss Deep and Shallow Clone in JavaScript jabo Landry ・ Nov 1 #webdev #javascript #programming #beginners https://lnkd.in/gYeFwW4e
To view or add a comment, sign in
-
If you are still struggling to understand some JavaScript trick concept of Deep and Shallow clone join me as I explore and break down how to deep and shallow clone and also how to apply them with confidence Let's discuss Deep and Shallow Clone in JavaScript jabo Landry ・ Nov 1 #webdev #javascript #programming #beginners https://lnkd.in/gYeFwW4e
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