Skip to content

Instantly share code, notes, and snippets.

View sejalkailashyadav's full-sized avatar
:octocat:
Focusing

SEJAL YADAV sejalkailashyadav

:octocat:
Focusing
View GitHub Profile

🧠 Is dynamic memory (using new and delete) necessary in C++?

Short Answer:

No, it’s not always necessary.


🔍 When You DON'T Need Dynamic Memory:

@sejalkailashyadav
sejalkailashyadav / fill everything again or scroll a lot.md
Last active May 8, 2025 11:33
fill everything again or scroll a lot.md

very common problem with large forms:

❌ When you submit a big form and Laravel validation fails, it refreshes the page and shows errors… 😩 But the user has to fill everything again or scroll a lot, which is frustrating.


✅ SOLUTION (Best Practice): Use old() values + show validation errors properly

You do NOT need to re-enter the entire form if you use Laravel’s built-in helpers the right way.


🔹 Core Concepts of OOP in JavaScript:

  1. Encapsulation: Bundling data (properties) and methods (functions) that work on the data into a single unit, usually a class. It hides the internal details of the object and only exposes what’s necessary.

  2. Abstraction: Hiding complex implementation details and showing only the necessary features to the user.

  3. Inheritance: The mechanism by which one class can inherit properties and methods from another class, allowing for code reuse and a hierarchical class structure.

Asynchronous Programming: Callbacks, Promises, and Async/Await

🔹 What is Synchronous in JavaScript?

Synchronous ka matlab hota hai — ek ke baad ek kaam hona.[sky- one by one]

Jaise ki:

Jab tak pehla kaam pura nahi hota, tab tak dusra start nahi hota.

Immutable Deep Update using Nested Maps:


🔁 Immutable Deep Update using Nested Maps

When working with nested data structures like arrays of objects (e.g., departments with employees), it's important to update values immutably — without modifying the original data.
This pattern uses nested .map() functions to update specific fields deep within the structure.


### ✅ You can use `map()` on:
1. **An array of values**
2. **An array of objects**
3. **An array of arrays**
Basically, any array.
---
### 🔹 1. **Array of values**

real-world data to show the difference between using map().flat() and flatMap().


Scenario: A List of Orders and Items

You have an array of orders, and each order contains an array of items. You want to flatten the items from all orders into a single list.

1. Using map() and flat()

@sejalkailashyadav
sejalkailashyadav / 202_Happy_Number.md
Last active December 16, 2024 12:38
Code Testcase Test Result Test Result 202. Happy Number

The Happy Number problem is about determining if a given number will eventually reach 1 by repeatedly replacing it with the sum of the squares of its digits. If the number reaches 1, it is called a happy number. Otherwise, if the process falls into a loop that does not include 1, the number is not happy.


Steps of the Problem

  1. Start with a positive integer n.
  2. Replace n with the sum of the squares of its digits.
    • For example: If n = 19, compute ( 1^2 + 9^2 = 1 + 81 = 82 ).
  3. Repeat the process:
  • For ( n = 82 ): ( 8^2 + 2^2 = 64 + 4 = 68 ).
  1. Algorithm

    • Definition: A step-by-step set of instructions to solve a problem.
    • Example: A recipe for baking a cake is like an algorithm—it tells you what to do in sequence.
  2. API (Application Programming Interface)

    • Definition: A way for different software systems to communicate.
    • Example: When you use Google Maps in a food delivery app, the app uses Google Maps' API to show directions.
  3. Cloud Computing