Day 26 of #30DaysOfJavaScript on LeetCode Today’s Challenge: 2625 – Flatten Deeply Nested Array Today’s problem was all about recursion and depth control. The task was to flatten a multi-dimensional array up to a given depth n, without using the built-in Array.flat() method. Here's my solution: var flat = function (arr, n) { if (n == 0) return arr; var ans = []; for (var i = 0; i < arr.length; i++) { if (Array.isArray(arr[i])) { ans.push(...flat(arr[i], n - 1)); } else { ans.push(arr[i]); } } return ans; }; 🔗 Try the problem here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #WebDevelopment #Developers #FrontEndDevelopment #30DaysOfCode #30DaysOfJavaScript
Flatten Deeply Nested Array with Recursion in JavaScript
More Relevant Posts
-
💻 JavaScript code should read like a story, not a puzzle. We've all seen the "Pyramid of Doom." You need to login, then get a user, then get their posts. Before you know it, you are ten brackets deep and can't find the way out. In our latest article entitled "The Secret Life of JavaScript: The Promise", we look at the evolution of async code: ✅ Callbacks: The nesting nightmare. ✅ Promises: The flat chain (The IOU). ✅ Async/Await: The "pause" button that doesn't freeze the browser. See how to turn your staircase logic into a straight line. 👉 Read it on Medium: https://lnkd.in/gmXQryaZ #JavaScript #Async #Coding #SoftwareDevelopment
To view or add a comment, sign in
-
-
Every React project becomes easier to scale when your folders are organized from day one. A clear structure leads to: Fewer bugs Faster debugging More time to focus on building real features. What the Cheatsheet Covers This guide breaks down how to structure the following elements to keep your project tidy and future-proof: Components Hooks Pages Services Assets Utils "Save this post; your next React project will thank you." Follow: Anwar Ali #ReactJS #ReactFolderStructure #WebDevelopment #FrontendDevelopment #JavaScript #CleanCode #CodingTips #ReactDevelopers #DeveloperCommunity #ProgrammingLife #SoftwareEngineering #LearnReact
To view or add a comment, sign in
-
-
Lecture 07 JavaScript Arrays Completed Today was all about arrays, and honestly-this lecture killed a lot of beginner misconceptions. Mentor: Rohit Negi Bhaiya. Covered Core methods: push, pop, splice Looping the right way (for vs for...of) Real-world methods: map, filter, reduce Mutating vs non-mutating methods Sorting, copying with spread, and finding elements The truth bomb: JS arrays are actually objects Big lesson: If you don't understand how arrays actually work, bugs are guaranteed. Slow progress, solid fundamentals. On to the next one #JavaScript #WebDevelopment #LearningInPublic #Frontend
To view or add a comment, sign in
-
-
Read the full guide here: 👉 https://lnkd.in/g8xPc26Y Stop memorizing JavaScript Closures. Start understanding them. 🧠 Closures are more than just an interview question—they are the "secret sauce" behind data privacy and advanced functional patterns. Think of a closure as a function carrying a "backpack" of variables from where it was born. 🎒 Even after the outer function finishes, that backpack stays alive. In my latest post, I break down: - Lexical Scope (The environment) - Variable Capture (The "backpack" logic) - Practical Use Cases (Beyond the theory) - Check out the deep dive and level up your JS game today! 🚀 #javascript #webdev #coding #frontend #softwareengineering
To view or add a comment, sign in
-
-
A Short Story About JavaScript's Async Journey... Once upon a time in Browserland, JavaScript would freeze EVERYTHING while waiting for coffee... Then came Callbacks: "Don't wait for me, I'll call you back!" But they created callback hell: 5 levels deep, unreadable code! ES6 brought Promises: Clean chains, better error handling. Yet we still thought in .then() chains... Finally, Async/Await arrived (ES8): Making async code look synchronous! With try/catch for errors, just like regular code! The unsung hero? The Event Loop - JavaScript's single-threaded multitasking wizard! See the complete evolution with code examples below 👇 Question: What's the worst callback hell you've encountered in legacy code? #Programming #AsyncAwait #Promises #Tech #SoftwareDeveloper #Angular #WebDevelopment #Frontend #InterviewPreparation #javaScript
To view or add a comment, sign in
-
🚀 Day 860 of #900DaysOfCode ✨ 7 Weird Things in JavaScript 👀 JavaScript is powerful… but let’s be honest — it can also be wonderfully weird. And understanding those “what just happened?” moments is exactly what helps you write more predictable, bug-free code. In today’s post, I’ve shared 7 strange, surprising, and often confusing behaviors in JavaScript — explained in a simple and intuitive way so you can finally make sense of them. Whether you're a beginner or an experienced dev, these insights will strengthen the way you think about JS under the hood. 👇 Which JS “weird behavior” surprised you the most when you first learned it? Tell me in the comments! #Day860 #learningoftheday #900daysofcodingchallenge #FrontendDevelopment #WebDevelopment #JavaScript #React #CodingCommunity #WTFJS #WebDevelopment #LearnJavaScript
To view or add a comment, sign in
-
The `this` keyword in JavaScript — explained simply 🧠 `this` confuses many developers at first. The key is: it depends on HOW a function is called. Normal Function 👇 • `this` refers to the object that calls the function • Value is dynamic Arrow Function 👇 • `this` does NOT have its own context • It takes `this` from the parent scope Simple rule to remember: Normal function → its own `this` Arrow function → borrows `this` This is why arrow functions are commonly used in: ✔ Callbacks ✔ React components ✔ Event handlers (carefully) Once this clicks, many bugs disappear 🚀 #javascript #frontenddeveloper #webdevelopment #coding #learningjavascript #reactjs #softwareengineering
To view or add a comment, sign in
-
-
🧠 This JavaScript Output Looks Impossible… But It Runs! Read carefully 👇 Don’t rush. console.log(Math.max()); console.log(Math.min()); console.log(Math.max(1, 2, 3)); console.log(Math.max([1, 2, 3])); No loops. No async. No tricky operators. Just Math. Still… the output surprises almost everyone 😄 🤔 Why this question feels different Hardly anyone practices empty arguments Shows how JS handles missing values Mixes numbers vs arrays in a subtle way Looks very beginner-friendly, but seniors pause 💬 Your Turn Comment your answers like this 👇 Line 1 → Line 2 → Line 3 → Line 4 → Try answering without running the code 🤓 I will post the correct output + simple explanation in the evening. 📌 Note: This is to understand JavaScript behavior, not to encourage confusing code. #JavaScript #FrontendDevelopment #LearnJS #CodingInterview #TechWithVeera #WebDevelopment #100DaysOfCode
To view or add a comment, sign in
-
-
Closures aren’t magic — they’re frozen scope living in memory 🧠 Closures confuse developers not because they’re complex, but because they’re explained poorly. A closure is simply a function that remembers its lexical scope, even after the outer function has finished executing. Once this mental model clicks, a lot of JavaScript behavior suddenly makes sense. 👉 Save this — closures take time to sink in. JavaScript Mastery The JavaScript Shop #javascript #closures #FrontendDevelopment #WebDevelopment #JavaScriptClosures #ProgrammingConcepts #CodingTips #SoftwareEngineering #Developers
To view or add a comment, sign in
-
🚀 Day 879 of #900DaysOfCode ✨ Prefer Primitives in `useEffect` Small decisions in React can have a big impact on performance — and dependency management in `useEffect` is one of them. In today’s post, I’ve explained why preferring primitive values in `useEffect` dependencies matters, and how it helps avoid unnecessary re-renders and unexpected effect executions. To make it clearer, I’ve also shared code examples that visually show the difference and the improvement. If you’ve ever faced confusing `useEffect` behavior, this post will help you think more clearly while writing effects. 👇 Have you ever struggled with `useEffect` dependencies? Share your experience in the comments! #Day879 #learningoftheday #900daysofcodingchallenge #FrontendDevelopment #WebDevelopment #JavaScript #React #CodingCommunity #useEffect #FrontendDevelopment #ReactPerformance
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