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
Remove Duplicates in Sorted Array with JavaScript
More Relevant Posts
-
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
To view or add a comment, sign in
-
-
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 16 / 30 – JavaScript Coding Challenge Problem: Given a string containing (), {}, and [], determine if the input string is valid. Solution: var isValid = function (s) { if (s.length % 2 !== 0) return false; let paraStack = []; let paraMap = { ")": "(", "}": "{", "]": "[" } for (const paras of s) { if (paras === "(" || paras === "{" || paras === "[") { paraStack.push(paras) } else { if (paraStack.pop() !== paraMap[paras]) { return false } } } return paraStack.length === 0 ? true : false };
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
-
-
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
-
Call, Apply, and Bind in JavaScript Understanding "this" in JavaScript can be tricky. That’s where call, apply, and bind come in. They allow you to control what this refers to. Here’s the difference: • call() → Invokes the function immediately, arguments passed individually • apply() → Invokes immediately, arguments passed as an array • bind() → Returns a new function with this bound (can be called later) Example: const obj = { name: "Tejas" }; function greet(message) { console.log(`${message}, ${this.name}!`); } greet.call(obj, "Hello"); // Hello, Tejas greet.apply(obj, ["Hi"]); // Hi, Tejas const newFn = greet.bind(obj); newFn("Namaskar"); // Namaskar, Tejas Why this matters: • Helps in function borrowing • Useful in event handlers • Commonly asked in interviews • Strengthens understanding of core JavaScript #JavaScript #WebDevelopment #FrontendDevelopment #Coding #Programming
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
-
-
JavaScript Scope & Closure — Concepts You MUST Know 💡 Understanding scope and closure is key to mastering JavaScript . 🔹 Scope determines where variables are accessible. Global Scope Function Scope Block Scope (let & const) 🔹 Closure is when a function “remembers” variables from its outer scope even after the outer function has finished execution. 👉 Simple Example: A function inside another function can access the parent function’s variables — that’s closure in action. 📌 Why it matters: Helps in data hiding (encapsulation) Used in callbacks, event handlers, and async code Essential for writing clean and efficient code 🚀 If you're preparing for interviews or building projects, mastering these concepts will level up your JavaScript skills. #JavaScript #WebDevelopment #FrontendDevelopment #Coding #Programming #MERNStack #InterviewPreparation #LearnToCode #Developers #TechSkills
To view or add a comment, sign in
-
💥 JavaScript: Where Logic Goes to Die 🤯 Think you understand JavaScript? These mind-bending quirks might change your mind… ⚡ Ever wondered: 👉 Why 9999999999999999 becomes 10000000000000000? 👉 Why 1 < 2 < 3 is true, but 3 > 2 > 1 is false? 👉 Why [] == false is true but [] === false is false? 🧠 Welcome to the world of: ✔️ Type Coercion ✔️ Floating Point Precision ✔️ Weird Comparisons ✔️ Truthy vs Falsy Values 💡 For example (from page 9): 0.1 + 0.2 === 0.3 → ❌ false Because JavaScript uses floating-point math, resulting in 0.30000000000000004 😂 And the classic: 'b' + 'a' + + 'a' + 'a' → “banana” (sort of 😅) 🚀 These aren’t bugs — they’re how JavaScript actually works! 📌 If you're a developer, mastering these quirks will save you from real-world bugs. 💬 Which one shocked you the most? #JavaScript #WebDevelopment #Coding #JS #Frontend #Programming #Developers #CodingLife
To view or add a comment, sign in
-
Day 6 / 30 - JavaScript Coding Practice Today’s problem: Roman to Integer var romanToInt = function (s) { if (s.length > 15) { return; } const romanMap = new Map([ ['I', 1], ['V', 5], ['X', 10], ['L', 50], ['C', 100], ['D', 500], ['M', 1000] ]); let sum = 0; let preValue = 0; for (let k = s.length - 1; k >= 0; k--) { let currentVal = romanMap.get(s[k]); if (currentVal < preValue) { sum -= currentVal; } else { sum += currentVal; } preValue = currentVal; } return sum; }; 💡 Key Insight: Instead of scanning from left to right, I iterated from right to left to easily handle subtraction cases like IV (4) and IX (9). 👉 If a smaller value comes before a larger one → subtract 👉 Otherwise → add #JavaScript #DSA #CodingPractice #ProblemSolving #100DaysOfCode #FrontendDevelopment
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