JavaScript Array Method Story : Raju Bhai ka Paisa Double Scam

10 minute mein 10 JavaScript array method samajh lo!

Β·

6 min read

Raju Bhai (on a call): Banwari, are Banwari! Mai Raju bol raha hu. Sun, mera ko na, ek bangla chahiye... aur ek usme private talab!

…Aur sun, bangla ke andar ek coding setup ho, RGB wali lighting ke sath, aur ek gaming chair bhi!

Babu Bhaiya: Are Raju! Tereko ek saath 8-10 lottery πŸ’° lag gayi kya re?

Raju Bhai: (Showing Off 😎): Nahi re Babu Bhaiya, yeh lottery-vottery garibon ke liye hoti hai… mai toh business πŸ’Ό karta hu!

Shyam (urf Ghanshyam): Kaisa business?

Raju Bhai: Batata hu! Ye Tata, Birla, Ambani… aur apna Devi Parsad ameer πŸ’° kaise bane, iska secret mil gaya hai!

Babu Bhaiya: Cigarette 🚬 pita hai.

Raju: Nahi re Babu Bhaiya, secret, secret! 🀫

Raju (further explaining):
Wo log kya karte hai na, sari paise cheat fund mein dalte hai… 21 din mein paisa double!
Babu Bhaiya (excited):
Phir 21 din baad paisa 4 guna! Phir 8 guna, 16 guna, 32 guna! Wah bhai!πŸ”₯πŸ’΅

Raju Bhai (show off): Isliye mana socha tum log ka liya 5-5 crore chodke jao!" 😎

Babu Bhaiya (rushing): La baba la!

Raju Bhai: Kya lau?

Babu Bhaiya: Mera 5 crore tune bola ne, 5 crore dega!

Raju Bhai: Aree! Amir aadmi dekha nahi ki bekaar ki tarah bhek manga shuru kar diya! Pehle Invest toh karna do! frr honga double Tum log laao 10-10 lakh rupee!

The ChitFund Array Magic! – JavaScript in Action

πŸ‘₯ Participants:
Raju Bhai, Babu Bhaiya, aur Shyam ne 10-10 lakh invest kar diya.

let chitFundKaPaise = ["10", "10", "10"];

Par abhi bhi 1 crore nahi hua! πŸ€”
Toh Raju Bhai ne Array Methods ka jaadu chalaya! 🎩✨

My Fav Array Method

1️⃣ .shift() 2️⃣ .pop() – O Sarak.. Sarak Udhar!

Raju Bhai (Excited, rushing to Pappu):
"Pappu! Sun, mere paas ek scheme hai! 25 din mein paise double ho jaayenge! Matlab, 25 din mein carorpati!"

Pappu (Curious):
"Mujhe bhi paise double karne hain!"

But jab Raju Bhai apne scheme ke baare mein bata raha tha, tab ek third person sun raha tha. Raju Bhai ne bola:
"O Sarak… Sarak udhar!"

Array Method - .pop()
Raju Bhai ne pop() method ka use karke pichhe baitha banda hata diya!

The pop() method of Array instances removes the last element from an array and returns that element. This method changes the length of the array.

jsCopyEditlet scheme = ["Pappu", "Third Person"];
scheme.pop(); // Removes "Third Person"
console.log(scheme); // ["Pappu"] // Ab scheme mein sirf Pappu hai!

Array Method - .shift()
Agar third person aage baitha hota, toh shift() use karte!

The shift() method of Array instances removes the first element from an array and returns that removed element. This method changes the length of the array.

jsCopyEditlet scheme = ["Third Person", "Pappu"];
scheme.shift(); // Removes "Third Person" from the front
console.log(scheme); // ["Pappu"]

3️⃣ .push() – Bhai, Paise Le Aaya!

Pappu (Excitedly):
Raju Bhai,maine bhi 20 lakh le aaye!"

Raju Bhai: Mast! ChitFund mein daal de!"

The push() method of Array instances adds the specified elements to the end of an array and returns the new length of the array.

chitFundKaPaise.push(20);
console.log(chitFundKaPaise); // ["10", "10", "10", "20"]

4️⃣ .filter() – Bangla Bechne ki condition!

Raju Bhai (looking at his chitFundKaPaise): Arre yaar, abhi bhi 50 lakh ki kami hai! Bangla bechna padega! Toh Raju Bhai house sale ke liye dealer ke paas gaya, aur dealer ne usko ek price list di:
[10, 20, 50, 70, 90]

Raju Bhai ko 50 lakh ki zarurat thi, toh usne .filter() method ki madad se ek condition apply ki:
"Agar apke paas 50 lakh hai, toh ap bangla kharid sakte ho!"

The filter() method of Array instances creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function

let housePrices = [10, 20, 50, 70, 90];
let filteredHousesPrice = housePrices.filter(price => price == 50);
console.log(filteredHousesPrice); // [50]

5️⃣ .concat() – Paise Jodne Ka Formula!

Raju Bhai ka pass ab do bag[array] hai filteredHousesPrice and chitFundKaPaise tho raju bhai .concat() method ko use krka paise ek bag mai dal diye updatedChitFund

The concat() method of Array instances is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

let updatedChitFund = chitFundKaPaise.concat(filteredHousesPrice);
console.log(updatedChitFund); // ["10", "10", "10", "20", "50"]

4️⃣ .reduce() – Total Paisa Kitna?

πŸ€” Raju Bhai: "Ab tak kitna paisa jamaa hua?" With help of reduce() method we find total amount.

let totalAmount = updatedChitFund.reduce((acc, curr) => acc + Number(curr), 0);
console.log("Total Money:", totalAmount);  // Output: Total Money: 100

βœ… 100 lakh (1 crore) collect! πŸŽ‰

6️⃣ .map() – Paisa Double!

😏 Babu Bhaiya: Raju! Tu bola tha paisa double hoga! Ab dikha apni magic trick!

Raju Bhai (smirking 😎): Babu Bhaiya, yeh dekho, map() ka jaadu! Har paise ka double*!"* πŸ€‘

let doubleMoney = updatedChitFund.map(paisa => paisa * 2);
console.log(doubleMoney); // [20, 20, 20, 40, 100]; Ek second mein paisa double! πŸ˜†

7️⃣ .find() – Sabse Bada Investor Kaun?

πŸ€” Babu Bhaiya:*"Dekhte hain kisne sabse zyada paisa invest kiya?"*

The find() method of Array instances returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.

let investors = [
  { name: "Pappu", amount: 20 },
  { name: "Shyam", amount: 10 },
  { name: "Babu Bhaiya", amount: 10 },
  { name: "Raju Bhai", amount: 10 }
];

let bigInvestor = investors.find(investor => investor.amount === Math.max(...investors.map(i => i.amount)));
console.log(bigInvestor); // { name: "Pappu", amount: 20 } Winner: Pappu! πŸŽ‰

9️⃣ .includes() – Paisa Safe Hai?

😨 Pappu: Mera paisa safe hai na?

πŸ˜† Raju Bhai: Dekhta hoon!

The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate.

let isPappuMoneySafe = updatedChitFund.includes(50);
console.log(isPappuMoneySafe); // true  βœ… Pappu ka paisa safe!

πŸ”Ÿ .slice() – Mujhe Mera Hissa De!

Pappu:
"Mujhe sirf pehle do investors ka paisa dekhna hai!"

Raju Bhai:
"Le beta, slice() ka use karke pehle do logon ka paisa nikal diya!"

jsCopyEditlet topTwoInvestors = ["Pappu", "Raju Bhai", "Babu Bhaiya", "Shyam"].slice(0, 2);
console.log(topTwoInvestors); // ["Pappu", "Raju Bhai"]

βœ… Sorted Share List!

Conclusion :

Aur is tarah Raju Bhai ne dikhaya ki kaise ek "scam wala dimaag" aur JavaScript ke array methods ka sahi istemal karke duniya ka chakkar chalaya ja sakta hai! πŸ”₯πŸ˜‚

βœ… .map() – Paisa double ho gaya!
βœ… .find() – Sabse bada investor kaun?
βœ… .filter() – Bechne ke liye sirf 50 lakh wale ghar!
βœ… .reduce() – Total kitna paisa jama hua?
βœ… .includes() – Bhai, paisa safe hai?
βœ… .concat() – Alag-alag jagah ka paisa ek jagah jamaa!

πŸ’‘ Moral of the Story:
JavaScript ke array methods sirf coding mein hi nahi, duniya ke har system mein kaam karte hain! Toh agali baar koi scheme suno, toh pehle socho – kahin yeh Raju Bhai ka chakkar toh nahi?

Β