JavaScript Array Method Story : Raju Bhai ka Paisa Double Scam
10 minute mein 10 JavaScript array method samajh lo!
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?