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
Implementing a custom filter function in JavaScript
More Relevant Posts
-
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
-
-
Day 4 of #30DaysOfJavaScript on LeetCode Today's challenge: 2665 — Counter II 🔁 The task was to create a createCounter function that accepts an initial integer init and returns an object with three functions: increment() → increases the value by 1 decrement() → decreases the value by 1 reset() → resets the value back to init Here’s my solution 👇 var createCounter = function(init) { let cache = init; return { increment: function() { return ++init; }, reset: function() { init = cache; return cache; }, decrement: function() { return --init; } }; }; This challenge was a good exercise in understanding closures and object methods — it’s cool how functions can maintain state in JavaScript! 💡 If you’d like to try it out, check it here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #Closures #30DaysOfCode #Functions #Objects #Programming
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
-
-
🚀 Understanding the difference between ++i and i++ in JavaScript Ever wondered what’s the real difference between ++i and i++ in JavaScript? They both add 1 to your variable — but timing is the key. ++i increases the value before it’s used. i++ increases the value after it’s used. It’s a tiny detail that can make a big difference, especially inside loops or complex expressions. #JavaScript #Programming #CodeTips #WebDevelopment
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
-
👋 Hello everyone! Today I'd practiced and solved ✅ coding questions on Javascript concepts like DOM Manipulations, functions and array methods. In this practice, 👉 I design Find the Index of the Numbers Page by using HTML and CSS, added functionality by using Javascript. 👉 If user enters a number it exists in numbers array then it shows the index of the number. 👉 If user enters a number it doesn't exists in numbers array then it shows the index of the number is "-1". Key Takeaways: ✅ DOM Manipulations using Javascript ✅ Handling user interactions using functions ✅ Array Methods #Day9 of #30Daysofcodingchallenge #Javascript #coding #programming #NxtWave #CCBP
To view or add a comment, sign in
-
Tired of JavaScript fundamentals feeling fuzzy? 🤯 If concepts like Hoisting, Closures, and Prototypes slow you down, you need a clearer reference. I've distilled the core structure rules of the language into Cheat Sheet Part 1: JavaScript Static Core for developers. Quickly Master: - Scope & TDZ: Variable boundaries (let/const vs var). - Hoisting Logic: What the engine really moves. - Closures: How functions create private memory. - Prototypes: The true foundation of JS inheritance. Stop guessing, start coding with confidence. ➡️ View the attached PDF now to get your free copy! 💾 #JavaScript #WebDevelopment #CodingTips #Programming #CheatSheet
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