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
"Implemented function composition in JavaScript for #30DaysOfJavaScript"
More Relevant Posts
-
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
-
Let’s decode three of the most confusing JavaScript topics 👇 🔹 1. Scope Scope defines where your variables and functions are accessible. Global Scope: Accessible everywhere in the code. Function Scope: Accessible only inside a function. Block Scope: (introduced with let & const) accessible only within { }. 🔹 2. Hoisting JavaScript moves declarations to the top of their scope before code execution. But remember — only declarations are hoisted, not initializations. That’s why var behaves differently than let and const. 🔹 3. TDZ (Temporal Dead Zone) The period between entering a scope and initializing a variable declared with let or const. Accessing a variable in TDZ results in a ReferenceError — it exists but isn’t accessible yet! #JavaScript #FrontendDevelopment #WebDevelopment #Coding #Programming #LearnToCode #Scope #Hoisting #TDZ
To view or add a comment, sign in
-
-
🚀 Callback Hell in JavaScript: The “Pyramid of Doom”! In JavaScript, Callback Hell happens when multiple asynchronous functions are nested inside each other, creating deeply indented code that’s hard to read, debug, and maintain. 😩 ✅ How to avoid it: Use Promises to flatten nested callbacks Use async/await for clean, readable code Modularize your logic into smaller functions #JavaScript #WebDevelopment #CallbackHell #AsyncAwait #Promises #CodingTips #FrontendDevelopment #WebDevelopers #CleanCode #Programming #LearnToCode #CodeSmarter #DeveloperCommunity
To view or add a comment, sign in
-
-
🚀 Day 8 of My 30 Days of JavaScript Journey ✅ Challenge: Function Composition (LeetCode #2629) Build a function compose(functions) that returns a new function representing the composition of all given functions. When called with an input x, it evaluates from right to left, applying each function in sequence. If no functions are provided, it returns the identity function — meaning f(x) = x. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gEXnFK4d 💡 Solution: https://lnkd.in/gjKcFQvB 🧠 Concept Highlighted: This challenge explores function composition, a key concept in functional programming, showing how multiple simple functions can combine to form powerful transformations. It reinforces the importance of execution order and function chaining in JavaScript. #Day8 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #FunctionalProgramming #LearningEveryday #ProblemSolving
To view or add a comment, sign in
-
Day 7 of #30DaysOfJavaScript: Solved the Function Composition Challenge! 🎉 Today's problem involved creating a function that composes an array of functions and applies them from right to left, just like mathematical function composition 𝑓(𝑔(ℎ(𝑥))) f(g(h(x))). Using JavaScript's reduceRight, I built a clean, efficient solution that handles composing any number of functions—even when the array is empty (returning the identity function). This challenge sharpened my understanding of higher-order functions and functional programming concepts. Here’s a quick look at the core idea: js const compose = (functions) => (x) => functions.reduceRight((acc, fn) => fn(acc), x); Example: Input functions: [x => x + 1, x => x * x, x => 2 * x] Input value: 4 Output: 65 Excited to keep growing and sharing every step in this coding journey! #JavaScript #LeetCode #FunctionalProgramming #CodeChallenge #WebDevelopment #LearningJourney #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 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
-
-
👋 Hello everyone! Today I'd practiced and solved ✅ coding questions on Javascript concepts like DOM Manipulations, functions, Event Listeners and HTTP Methods. In this practice, 👉 I design HTTP Get Method Practice Page by using HTML and CSS, added functionality by using Javascript. 👉 Making HTTP Request (GET Method) using fetch() method. 👉 When we click on "Send Get Request" button it shows "loading" while making HTTP Request. 👉 The Request status section shows the status code. 👉 The Response Body shows the HTTP response. Key Takeaways: ✅ DOM Manipulations using Javascript ✅ Handling user interactions using functions ✅ Event Listeners ✅ HTTP Methods #Day17 of #30Dayscodingchallenge #coding #programming #Javascript #NxtWave #CCBP
To view or add a comment, sign in
-
JS Tutorial #1: Introduction to JavaScript Title: JS Tutorial #1: What is JavaScript and How It Works Content: JavaScript is a programming language used to make web pages interactive. It runs in the browser and can also run on the server using Node.js. Code snippet: console.log("Hello, Cognothink!"); Engagement: Try running this in your browser console. What message do you see? Comment below! #JavaScript #Coding #LearnJS #WebDevelopment #Cognothink
To view or add a comment, sign in
-
💻 Day 2 — Learning to Think in Logic 🧠 Today was all about decision making in JavaScript — learning how code “thinks.” I explored conditional statements: if, else if, switch, and even played around with alert, prompt, and error handling. It’s wild how these simple tools form the foundation of every program’s logic. Each concept feels like another small piece of the bigger picture coming together. Still early days — but every line of code is one step closer to clarity and confidence. 🌱 #Day2 #CodingJourney #MERNStack #LearnInPublic #JavaScript
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