Day 33: Implementing an array flattener. Focusing on the logic behind converting nested arrays into a single-dimensional structure. While JavaScript provides the flat method, writing a manual implementation using recursion helped clarify how to traverse unknown depths of data. Key takeaways: Recursion base cases: Identifying when an element is a primitive value versus another array. Method overhead: Understanding the difference between built-in methods and custom recursive functions in terms of readability and performance. Data manipulation: Practical applications in handling complex API responses where data is often deeply nested. #JavaScript #WebDevelopment #CodingJourney #Frontend #ComputerScience
Implementing Array Flattener in JavaScript
More Relevant Posts
-
Ever changed a variable in JavaScript only to realize you accidentally broke the original data too? 🤦♂️ That’s the classic Shallow vs. Deep Copy trap. Here is the "too long; didn't read" version: 1. Shallow Copy (The Surface Level) When you use the spread operator [...arr] or {...obj}, you’re only copying the top layer. The catch: If there are objects or arrays inside that object, they are still linked to the original. Use it for: Simple, flat data. 2. Deep Copy (The Full Clone) This creates a 100% independent copy of everything, no matter how deep the nesting goes. The easy way: const copy = structuredClone(original); The old way: JSON.parse(JSON.stringify(obj)); (Works, but it’s buggy with dates and functions). The Rule of Thumb: If your object has "layers" (objects inside objects), go with a Deep Copy. If it’s just a basic list or object, a Shallow Copy is faster and cleaner. Keep your data immutable and your hair un-pulled. ✌️ #Javascript #WebDev #Coding #ProgrammingTips
To view or add a comment, sign in
-
-
Problem: Design HashMap My Approach (Simple Implementation 🛠️): This problem focuses on designing a HashMap from scratch without using built-in map structures I implemented it using a JavaScript object {} 👉 put(key, value) → Insert or update key-value pair 👉 get(key) → Return value if key exists, else -1 👉 remove(key) → Delete the key if present Core Logic: Store data in an object Use direct key access for O(1) operations Use delete to remove entries Complexity: put: O(1) get: O(1) remove: O(1) What can be improved? 👀 👉 This relies on built-in hashing 👉 A deeper implementation would involve: Buckets (array of lists) Handling collisions Custom hash functions Learning takeaway: Understanding how maps work internally is crucial #LeetCode #DSA #HashMap #DataStructures #Algorithms #JavaScript #ProblemSolving #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
Most developers think they understand arrays… until they face nested data. I wrote about one of those deceptively simple problems in JavaScript — Array Flattening. link 🔗 https://lnkd.in/dncTScA7 If you’ve ever struggled with deeply nested arrays or recursion, this one will hit differently
To view or add a comment, sign in
-
-
🚀 Learning by Building: Mastering Frequency Patterns in JavaScript Today I worked on a classic algorithm problem: finding the most frequent element in an array using a HashMap (Map in JavaScript). Here’s the idea: 👉 Traverse the array 👉 Count occurrences using a Map 👉 Track the maximum frequency in real-time This approach is efficient (O(n)) and widely used in real-world scenarios like data analysis, caching, and optimization problems. 💻 Example result: Input: [1, 3, 2, 1, 4, 1, 2, 1, 5, 3] Output: { value: 1, count: 4 } I’m currently practicing patterns and strengthening my problem-solving skills step by step. 📌 Check out my full exercises here: https://lnkd.in/ej4fNeZs Consistency > Talent. #JavaScript #Algorithms #ProblemSolving #SoftwareEngineering #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
Built an efficient LRU Cache from scratch using JavaScript. Key highlights of the implementation: Designed a custom Doubly Linked List for O(1) insertions and deletions Used a HashMap to achieve constant-time access Ensured optimal eviction strategy by always removing the least recently used node Maintained strict O(1) time complexity for both get and put operations Performance: Runtime: 102 ms (faster than ~57% of submissions) Memory: 113.67 MB This problem reinforced how combining data structures (HashMap + DLL) leads to highly optimized systems — a pattern widely used in real-world caching systems like databases and browsers. Continuing to focus on writing clean, efficient, and scalable code. #DataStructures #Algorithms #JavaScript #SystemDesign #Coding
To view or add a comment, sign in
-
-
Day 04 of Learning JavaScript Deep Today’s topic looked simple… but turned out to be powerful Traversing an Array - Visiting each element one by one. Example: let arr = [10, 20, 30, 40]; for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } 🧠 Key understanding: Arrays start at index 0 End at length - 1 One mistake can break logic 👇 for (let i = 0; i <= arr.length; i++) { console.log(arr[i]); // undefined at end ❌ } 💭 Simple thought: “Array is just data… Traversal is how you understand it.” Small concept… big impact 🔥 #Day04 #JavaScript #FrontendDevelopment #LearningDeep #Traversing #Arraybasics
To view or add a comment, sign in
-
Sometimes the biggest bottleneck in your code isn't the algorithm itself, but how the language handles memory. 💻 Just crushed a complex query problem with a 100% runtime. To get the execution time this low (389ms), I had to step away from standard JavaScript practices and optimize for the machine: Instead of creating new arrays and triggering heavy GC pauses, I allocated a BigUint64Array exactly once and overwrote it. By combining this with Square Root Decomposition for modular arithmetic, the processing time plummeted. A great reminder that when dealing with large datasets, thinking about memory allocation and data types is just as important as the logic itself. #CodingJourney #JavaScript #DataEngineering #Optimization #LeetCode
To view or add a comment, sign in
-
-
Difference between fundamental data structures used in JavaScript: - If you need to access items by index, you should probably be using an Array. - If you need to access items by key, you should probably be using an Object. - If you need to access items by value, you should probably be using a Map. - If you need to store unique items and perform operations on that collection, you should probably be using a Set. #javascript #concepts #developer #coding #engineer
To view or add a comment, sign in
-
🚀 Just built a simple Live Name Filter using JavaScript Today I practiced DOM manipulation + events + regex and created a small project where: ✔️ User types their name in input field ✔️ Only letters (a-z, A-Z) & spaces are allowed ✔️ Invalid characters are automatically removed ✔️ Input is displayed live in a heading 💡 Concepts I used: DOM Selection (querySelector) Event Handling (input event) String methods (replace) Basic Regex ([^a-zA-Z ]) Small steps every day towards becoming a better developer 💻🔥 #JavaScript #WebDevelopment #LearningInPublic #CodingJourney #Frontend #ApnaCollege
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