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
More Relevant Posts
-
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
-
-
🚀 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
-
Deep Javascript Series Question 1: interviewer: “Can you explain how the JS event loop functions?” me: The event loop works like a traffic supervisor. JavaScript handles one task at a time. When asynchronous actions occur, like setTimeout or fetch, they take place outside the main thread. Once the stack is clear, the event loop looks for: - Microtasks: Promises, MutationObservers - Macrotasks: setTimeout, setInterval, I/O Microtasks always come first. That’s why a Promise callback runs before a setTimeout(…, 0). JavaScript doesn’t run in parallel; it just waits. #JavaScript #WebDevelopment #FrontendDevelopment #Developers #BuildInPublic #Programming #DeepJavaScript #TechCommunity #CodingJourney
To view or add a comment, sign in
-
Topic: "Understanding JavaScript Operators" 📝 Post: Today I learned about JavaScript Operators — special symbols used to perform operations on values and variables. They help us do calculations, make comparisons, and control logic in our programs. Here are a few common types 👇 Arithmetic Operators – used for basic math operations let a = 10, b = 5; console.log(a + b); // 15 (Addition) console.log(a - b); // 5 (Subtraction) console.log(a * b); // 50 (Multiplication) Comparison Operators – used to compare two values console.log(a > b); // true console.log(a === b); // false Logical Operators – used to combine conditions console.log(a > 0 && b > 0); // true (AND) console.log(a > 0 || b < 0); // true (OR) console.log(!(a === b)); // true (NOT) Learning these helps write conditions and calculations easily in JavaScript! 🚀 #JavaScript #WebDevelopment #LearnToCode #FrontendDevelopment #ProgrammingBasics #CodingJourney #100DaysOfCode #TechLearning #DeveloperCommunity
To view or add a comment, sign in
-
#7: Control Flow & Iterations in JavaScript! 🚀 Just wrapped up another core chapter of my JS journey — understanding how decisions and loops drive program logic. Here’s what I explored today: 🔹 Control Flow & Conditional Statements ✅ if, else if, else — mastering decision-making ✅ Comparison operators (===, !==, >, <, etc.) ✅ Logical operators (&&, ||) for combined conditions ✅ Shorthand execution methods for cleaner code 🔹 Switch Statements ✅ Cleaner multi-condition handling ✅ Importance of break and default 🔹 Truthy & Falsy Values ❌ Falsy: false, 0, "", null, undefined, NaN ✅ Truthy surprises: "0", "false", " ", [], {}, function(){} 💡 Learned: Check arrays with .length & objects using Object.keys() 🔹 Advanced Operators ✅ Nullish Coalescing (??) → safer than || for null/undefined ✅ Ternary Operator → condition ? true : false (clean & compact) 🔹 Loops & Iterations ✅ for loops (including nested + multiplication tables) ✅ while & do-while (executes at least once!) ✅ break to exit | continue to skip 📍 Key Insights: ✔ Use === for strict equality ✔ [] is truthy → always check .length ✔ ?? > || when dealing with null/undefined ✔ Ternaries keep logic short but readable The deeper I go into JavaScript, the more powerful and enjoyable it becomes! 💪 💬 Let’s discuss — which control flow concept took you the longest to grasp? 👇 #JavaScript #Programming #WebDevelopment #CodingJourney #LearnToCode #SoftwareDevelopment #TechSkills
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
-
-
🚀 #Day27 #Cohort2.0| Sheryians Coding School| #Javascript |#part3 Today’s session was about JavaScript concepts that form the real foundation of programming logic. ✅Here’s a quick summary of what I learned today 👇 1️⃣ Variables – var, let, and const 🔸 var is function-scoped (the old way), 🔸 while let and const are block-scoped 🔸 value is fixed in const (no change once declare) 🔸In let value can be re-declare and change 2️⃣ Console Methods Tried out several console functions: 🔸console.log() for normal output 🔸console.info() for informational messages 🔸console.warn() for warnings ⚠️ 🔸console.error() for errors ❌ 🔸console.table() for visualizing data neatly in tables 🔸console.dir() for seeing the structure of objects clearly 3️⃣ Prompt & Alert 🔸alert() ->for showing messages 🔸prompt() -> for taking quick input from the user. 4️⃣ Strings 🔸 Denoted by " ", ' ' 🔸" no. + any character/special symbol " -> " " string ✅slice() ->to extract a part of the string ✅split() ->to break text into arrays ✅replace() & replaceAll-> to change specific parts ✅includes() -> to check if a word exists inside a string 5️⃣ Template Strings (Template Literals) Used backticks ` ` instead of quotes to create cleaner and dynamic strings. The best part? You can directly use variables inside like this: `Hello ${name}, welcome back!` ✨ Every session in Cohort 2.0 is helping me sharpen my basics and think like a real developer - step by step. Learning how these small concepts connect to build bigger projects is truly satisfying. Thank you Harsh Vandana Sharma bhaiya for the wonderful lecture. #JavaScript #WebDevelopment #LearningJourney #Cohort2_0 #FrontendDevelopment
To view or add a comment, sign in
-
-
One of the most valuable features of functional programming is the ability to work with lazy sequences. Today, nearly every programming language supports generics, functions as values, and iterators. These are essential building blocks for operators that work with lazy sequences. In the next series of posts, we will build my JavaScript library, powerseq, from scratch. https://lnkd.in/dTdM5snr
To view or add a comment, sign in
-
🚀 Efficient Task Scheduling with JavaScript (LeetCode 621: Task Scheduler) Today I explored an interesting problem — scheduling tasks with cooldown periods efficiently. 🔹 Problem: Given a list of tasks (like ['A', 'A', 'A', 'B', 'B', 'B']) and a cooldown interval n, find the least number of intervals needed to finish all tasks without breaking the cooldown rule. 🔹 Key Idea: Count the frequency of each task. Sort to find the most frequent task. Use idle slots to manage cooldowns. Minimize idle time and calculate total intervals. 💡 Learning: This problem taught me how to use frequency counting, sorting, and greedy scheduling together to reduce idle time and improve performance. #JavaScript #TypeScript #Coding #ProblemSolving #LeetCode #WebDevelopment #TechLearning
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