Day 10 / 30 - Javascript Coding Challenge Problem: Given an array of functions [f1, f2, f3, ..., fn], return a new function fn that is the function composition of the array of functions. The function composition of [f(x), g(x), h(x)] is fn(x) = f(g(h(x))). The function composition of an empty list of functions is the identity function f(x) = x. You may assume each function in the array accepts one integer as input and returns one integer as output. Solution: var compose = function (functions) { return function (x) { let sum = x; for (let k = functions.length - 1; k >= 0; k--) { sum = functions[k](sum) } return sum } }; #JavaScript #FunctionalProgramming #DSA #CodingPractice #100DaysOfCode #FrontendDevelopment
Compose Function from Array of Functions in JavaScript
More Relevant Posts
-
Day 9 / 30 - Javascript Coding Problem: Given an integer array nums, a reducer function fn, and an initial value init, return the final result obtained by executing the fn function on each element of the array, sequentially, passing in the return value from the calculation on the preceding element. This result is achieved through the following operations: val = fn(init, nums[0]), val = fn(val, nums[1]), val = fn(val, nums[2]), ... until every element in the array has been processed. The ultimate value of val is then returned. If the length of the array is 0, the function should return init. Please solve it without using the built-in Array.reduce method. Solution: var reduce = function (nums, fn, init) { let numsLength = nums?.length; if (numsLength === 0) { return init; } let acc = init; for (let k = 0; k < numsLength; k++) { acc = fn(acc, nums[k]); } return acc; }; #JavaScript #DSA #CodingPractice #100DaysOfCode #FrontendDevelopment #ProblemSolving
To view or add a comment, sign in
-
-
Day 17 / 30 – JavaScript Coding Challenge Problem: Remove duplicates in-place from a sorted array and return the count of unique elements. Solution: var removeDuplicates = function (nums) { if (nums.length === 0) return 0; let i = 0; for (let j = 0; j < nums.length; j++) { if (nums[j] !== nums[i]) { i++; nums[i] = nums[j]; } } return i + 1; }; #JavaScript #DSA #CodingPractice #100DaysOfCode #ProblemSolving #FrontendDevelopment
To view or add a comment, sign in
-
-
JavaScript: Logical Operators 🧠 Want to make smart decisions in JavaScript code? Learn Logical Operators. Logical operators help your program decide what should happen next. They are used in conditions, validations, and real-world logic. Here are the 3 main ones 👇 • AND (&&) Both conditions must be true age > 18 && hasLicense • OR (||) At least one condition must be true isAdmin || isEditor • NOT (!) Reverses the result !isLoggedIn These operators are used in if statements, authentication checks, form validation, and many real projects. Small concept. Very powerful in coding. #JavaScript #WebDevelopment #FrontendDevelopment #ProgrammingBasics #LearnJavaScript #CodingForBeginners #SoftwareEngineering #DeveloperTips #TechLearning #CodeNewbie
To view or add a comment, sign in
-
-
🚀 Master JavaScript String Methods Like a Pro! If you're working with text in JavaScript, these string methods will make your life much easier 👇 🔹 slice() – Extract a part of a string 🔹 substring() – Get text between two positions 🔹 replace() – Replace text with something new 🔹 toUpperCase() / toLowerCase() – Change text case 🔹 includes() – Check if a value exists in a string 💡 These small methods are powerful when building real-world applications like search, validation, and data formatting. 👉 Start using them today and level up your JavaScript skills! What’s your favorite JavaScript method? Let me know in the comments 👇 #JavaScript #WebDevelopment #Frontend #Coding #Programming #Developers #LearnToCode #100DaysOfCode #Tech
To view or add a comment, sign in
-
-
Day 15 / 30 - Javascript Coding practice Problem : Longest Common Prefix Find the longest common prefix among an array of strings. If there’s no common prefix, return an empty string "". Solution: var longestCommonPrefix = function (strs) { let longestStr = strs[0] for (let k = 1; k < strs.length; k++) { let j = 0; while (j < strs[k].length && j < longestStr.length && strs[k][j] === longestStr[j]) { j++; } longestStr = longestStr.slice(0, j) if (longestStr === "") return "" } return longestStr; }; #JavaScript #DSA #CodingPractice #100DaysOfCode #ProblemSolving #FrontendDevelopment
To view or add a comment, sign in
-
-
🚨 7 JavaScript Facts That Will Blow Your Mind 🤯 Think you know JavaScript? Wait till you see these 👇 1️⃣ NaN !== NaN 👉 Not even equal to itself 2️⃣ [] + [] = "" 👉 Empty arrays become an empty string 3️⃣ null + 1 = 1 👉 null is converted to 0 4️⃣ typeof null === "object" 👉 This is a bug in JavaScript 5️⃣ 0.1 + 0.2 !== 0.3 👉 Floating point precision issue 6️⃣ == vs === 👉 Always prefer === (strict equality) 7️⃣ JavaScript is single-threaded 👉 Handles async using the event loop 💡 One line to remember: 👉 “JavaScript is simple… until it’s not 😏” 💬 Which fact surprised you the most? 📌 Save this for interviews & quick revision #javascript #webdevelopment #frontend #coding #programming #javascriptdeveloper #learncoding #developers #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Learning JavaScript? Start with Strings. Strings are one of the most used things in JavaScript. If you can work with text, you can build forms, messages, search features, and much more. Let’s understand the basics 👇 • Create a string using quotes let name = "JavaScript"; • Find string length name.length • Join strings together "Hello " + "World" • Change text case name.toUpperCase() or name.toLowerCase() • Get part of a string name.substring(0,4) Small concept… but used everywhere in real projects. Master the basics → coding becomes easier. #JavaScript #WebDevelopment #FrontendDevelopment #LearnToCode #ProgrammingBasics #JavaScriptTips #CodingForBeginners #DeveloperCommunity #TechEducation #SoftwareDevelopment
To view or add a comment, sign in
-
-
Spread and Rest in JavaScript use the same ... syntax but behave differently. • Spread expands values • Rest collects values In this blog, I’ve explained both with clear examples using arrays, objects, and practical use cases 👇 https://lnkd.in/g3p4YVH4 #javascript #webdevelopment #frontend #coding #programming #learninpublic
To view or add a comment, sign in
-
Wrote a new blog on Async/Await in JavaScript: Writing Cleaner Asynchronous Code Covering: • Why async/await was introduced • How async functions actually work • The await keyword concept • Error handling with async code • Comparison with promises https://lnkd.in/gT3R_e5c #JavaScript #WebDevelopment #AsyncAwait #FrontendDevelopment #Programming #Coding #SoftwareEngineering #Developers
To view or add a comment, sign in
-
Scope vs Closure in JavaScript — Explained Simply Understanding the difference between Scope and Closure is crucial for writing clean and efficient JavaScript code. While Scope defines where variables are accessible, Closure allows functions to remember their lexical environment even after execution. This concept is widely used in: • Data encapsulation • Function factories • Callbacks & async programming If you’ve ever been confused between these two, this guide will help you clear it with practical examples. 👉 Read the full article: https://lnkd.in/ga8WaNiA #JavaScript #FrontendDevelopment #WebDevelopment #Programming #Coding #SoftwareDevelopment #LearnJavaScript #InterviewPrep
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