Skip to content

Instantly share code, notes, and snippets.

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

SEJAL YADAV sejalyadav0818

:octocat:
Focusing
View GitHub Profile
@sejalyadav0818
sejalyadav0818 / 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()

@sejalyadav0818
sejalyadav0818 / 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

HTTP Methods in RESTful APIs (Elaborated)

RESTful APIs rely on standard HTTP methods to perform operations on resources. Here's an in-depth look:

  1. GET (Retrieve Data)
    • Purpose: Fetch data from the server.
    • Characteristics:
      • Safe: It doesn't modify any data on the server.
      • Idempotent: Multiple identical requests return the same result.
  • Example: