🔥 Day 26 of #30DaysOfJavaScript #LeetCode 2705: Compact Object Today I worked on a really interesting problem — building a recursive function that removes all falsy values from an object or array, including deeply nested ones. Falsy values include: false, 0, "", null, undefined, NaN The twist? 👉 Arrays are also treated as objects 👉 And we must compact every nested level 👉 Without using any built-in magic ✨ 🧠 Key Learnings ✅ Recursion is perfect for tree-like structures ✅ Array.isArray() helps treat arrays differently ✅ Boolean(value) is a clean way to test truthiness ✅ JSON constraints simplify the problem #JavaScript #LeetCode #30DaysOfCode #WebDevelopment #ProblemSolving #CodingJourney
Compact Object with Recursion and JavaScript
More Relevant Posts
-
Built an MCQs Extractor using vanilla JavaScript ! Users simply write MCQs where: • Question ends with ? • Options are separated by line breaks • Correct answer is marked with * The system automatically extracts and displays clean MCQs What I Learned: This project helped me deeply understand string operations, text parsing, Symbol-based logic (? and *) and how map with return + join is essential when generating HTML dynamically. Small project. Big learning. GitHub Repository: https://lnkd.in/dkykFcwf Live Demo (Netlify): https://lnkd.in/dZWsT2G6 #JavaScript #WebDevelopment #FrontendDevelopment #MCQsExtractor #StringMethods #MapAndJoin #LearningByDoing #CodingJourney #DevelopersHub
To view or add a comment, sign in
-
Day 82 of #100DaysOfLinkedIn — Type Narrowing & Type Guards in TypeScript Today I learned how TypeScript narrows types using conditions and type guards, allowing the compiler to understand what type a variable really is at runtime. This is a very important concept when working with union types, APIs, and real-world data. What I learned today: • What type narrowing means • Using typeof for primitive checks • Using in operator for object checks • Using instanceof for class checks • Writing custom type guards • Preventing runtime errors with safe checks This makes TypeScript smarter and safer, especially in complex logic. #TypeScript #JavaScript #WebDevelopment #FrontendDevelopment #MERNStack #100DaysOfLinkedIn #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
1. Two Sum (#LeetCode – Easy) Today I revisited one of the most popular DSA problems: Two Sum. The goal is simple—find two indices in an array whose values add up to a given target but the key is doing it efficiently. * Approach: I used a hash map to store previously seen numbers and their indices. For each element: - Calculate its complement (target - current number) - Check if the complement already exists in the map - If yes, return both indices immediately - This reduces the time complexity from O(n²) to O(n) * Why this works well: - Single pass through the array - Efficient lookup using Map - Clean and readable logic #LeetCode #JavaScript #DSA #ProblemSolving #CodingPractice #SoftwareEngineering #LearningEveryDay
To view or add a comment, sign in
-
-
📌 LeetCode Solved | LC-859: Buddy Strings ✅ Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false. 🧠 Thought Process Instead of trying all swaps (which screams inefficiency), I leaned on logical cases. Case 1: Strings already equal If s === goal, a swap is still required — so the string must contain at least one duplicate character. Otherwise, swapping would change it. Case 2: Strings are different Traverse once and record indices where characters differ. A valid solution exists only if exactly two indices differ. Check whether swapping those two characters aligns both strings. ⚙️ Performance Time Complexity: O(n) Runtime: 0 ms (Beats 100%) 🚀 Space: Minimal, just tracking mismatches #LeetCode #DSA #ProblemSolving #JavaScript #Strings #CodingJourney #Consistency #LearnInPublic
To view or add a comment, sign in
-
-
What does this print? (Hint: Most developers get it wrong.) I thought I UNDERSTOOD JAVASCRIPT loops... until I saw this bug. 😅 Quick quiz: What does this code print? for (var i = 0; i < 3; i++) { setTimeout(() =>console.log(i), 1000); } If you said 0, 1, 2, you’re falling into the same trap I did early. THE ACTUAL OUTPUT IS 3, 3, 3. Why? It comes down to Scope and the Event Loop: var is function-scoped (not block-scoped). The setTimeout callback doesn't run until the loop has already finished. By the time the console logs, i has already been incremented to 3. The Fix? Simply switching to let (block-scoping) or using a closure. It’s a classic example of why understanding the engine under the hood is more important than just knowing the syntax. Have you ever been burned by var in a modern codebase? #JavaScript #WebDev #CodingTips #SoftwareEngineering
To view or add a comment, sign in
-
-
🌞 Day 39 – LeetCode 75 ✅ 199. Binary Tree Right Side View Today’s problem: return the right-side view of a binary tree. Approach – Level Order (BFS) : I used a queue + level order traversal: - Start with queue = [root]. For each level: - Take size = queue.length (number of nodes in this level). - Process nodes one by one using shift(): When i === size - 1, it means this is the rightmost node of the current level → push node.val into result. - Push node.left and node.right into the queue (if they exist) for the next level. By always picking the last node of each level, we directly build the right-side view. Complexity : Time: O(n) Space: O(h) #LeetCode75 #Day39 #LeetCode #DSA #JavaScript #BinaryTree #BFS #ProblemSolving #CodeEveryday #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
When something breaks in JS, knowing the type of error makes debugging way easier. ❌ SyntaxError Code is written incorrectly — JS can’t even start running it ❌ ReferenceError Trying to use something that doesn’t exist (variable or function not defined) ❌ TypeError Using a value in the wrong way (calling something that’s not a function, accessing undefined) Why it matters: ✅ Debug faster ✅ Fix the root cause ✅ Avoid random console guessing Errors aren’t the problem, understanding them is. Which one do you encounter most often? #JavaScript #JSBasics #FrontendDeveloper #WebDevelopment #Debugging #LearningInPublic
To view or add a comment, sign in
-
Mastering JavaScript: The Power of .reduce(): The Array.reduce() method is a powerhouse in JavaScript, often hailed as the "Swiss Army Knife" for array transformations. While it might seem a bit intimidating at first glance, understanding its core principle can unlock a new level of efficiency and elegance in your code. Think of reduce as a data synthesizer: it takes an array of individual items and, through a "reducer" function, combines them step-by-step into a single, accumulated result. This could be a sum, an object, or even a flattened array! I recently tackled LeetCode Problem 2626: "Array Reduce Transformation," which challenged us to implement our own version of this fundamental method. Here's a clean, efficient solution: #JavaScript #WebDevelopment #CodingTips #FunctionalProgramming #JavaScript #LeetCode #WebDevelopment #CodingChallenge #SoftwareEngineering #ProgrammingTips #FrontendDevelopment #DataTransformation #TechSolutions
To view or add a comment, sign in
-
-
JavaScript Notes to Escape Tutorial Hell (16/20) Is JavaScript an Interpreted language or a Compiled language? If you said "Interpreted," you are technically... 10 years behind. Modern JavaScript uses JIT (Just-In-Time) Compilation This deck explains: - What a JavaScript Runtime Environment really is - The role of the JavaScript Engine - How JIT compilation works - How code is converted into an AST (Abstract Syntax Tree) - Interpreter vs Compiler working together - What the Call Stack and Memory Heap do - How the Garbage Collector manages memory Understanding JIT is why you know that writing stable, predictable object shapes makes your code run faster. #JavaScript #WebDevelopment #JIT #V8Engine #Compilers #CodingJourney #SoftwareEngineering #InterviewPrep #FrontendDeveloper
To view or add a comment, sign in
-
🚀 JavaScript LeetCode Challenge 🧩 Problem: 2634 – Filter Elements from Array Today I learned how filtering works behind the scenes in JavaScript without the filter function 👨💻 This problem helps build a strong foundation for: ✔ Callbacks ✔ Higher-order functions ✔ Array manipulation Consistency > Motivation 💯 One problem a day makes you ready 💪 🎥 Full live solution on YouTube (https://lnkd.in/g4xTBvm8) #JavaScript #LeetCode #DSA #FrontendDeveloper #CodingLife #100DaysOfCode #javascriptdeveloper #leetcodechallenge #webdeveloper #frontendinterview #codingdaily #programminglife
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