Table of contents
- ๐Welcome to Team Hitesh & Piyush Dev Academy!
- ๐ค What is a Polyfill?
- ๐ Mission 1: myMap() โ "Hitesh Sir Trains Every Dev!"
- ๐ Mission 2: myForEach() โ "Akash Sir, Mukul Sir and All TAโs Gives Individual Coaching!"
- ๐ Mission 3: myFilter() โ "Only the Best Coders Stay in the Team For Open-Source FreeAPI!"
- ๐ Mission 4: myReduce() โ "Building the Ultimate Dev Skillset!"
- ๐ Mission 5: myFind() โ "Finding the Lead Developer(Superhero Dev)!"
- ๐ฆธโโ๏ธ Mission 6: mySome() โ "Not Everyone Makes It, But the Few Heroes Will!"
- โก Mission 7: myEvery() โ "Every Hero in the Team Must Be Strong!"
- ๐ Mission 8: myIncludes() โ "Checking for Team Members!"
- ๐ช Mission 9: mySort() โ "Sorting the Team Based on Skills!"
- ๐ Mission 10: myConcat() โ "Uniting Powers for the Ultimate Team!"
- ๐ Congratulations, You Are Now a JavaScript Chaicode Team Player!
- Whatโs Next?
- Time to Rise and Shine!
- ๐ฏ Mission Accomplished. Now Go Create Your Future!
๐Welcome to Team Hitesh & Piyush Dev Academy!
Hey there, future JavaScript champ! ๐ Imagine Hitesh & Piyush Sir are creating a legendary dev team ๐ปโก, and they want YOU to be a part of it! But before you join, you need to train like a true coding warrior. Ready? Letโs go! ๐
๐ค What is a Polyfill?
Imagine you're in a dev team, and one member doesnโt know a certain skill. To make the team stronger, you teach them! Thatโs exactly what a polyfill doesโit helps JavaScript understand a method it doesnโt know!
Today, weโll teach JavaScript some new tricks by building our own superhero methods! ๐งโโ๏ธ๐ฅ
๐ Mission 1: myMap() โ "Hitesh Sir Trains Every Dev!"
Every dev in the team must level up! Hitesh Sir ensures each one gets trained and returns stronger. Thatโs what map()
doesโit transforms each element in an array.
Array.prototype.myMap = function(callback) {
let result = [];
for (let i = 0; i < this.length; i++) {
result.push(callback(this[i], i, this));
}
return result;
};
๐ฏ Example:
let skills = ["HTML", "CSS", "JS"];
let upgradedSkills = skills.myMap(skill => skill + "++");
console.log(upgradedSkills); // ["HTML++", "CSS++", "JS++"] Now you have a super power ++
๐ Mission 2: myForEach() โ "Akash Sir, Mukul Sir and All TAโs Gives Individual Coaching!"
All TAโs are personally guides each dev and gives feedback. Thatโs what forEach()
doesโit goes through every element.
Array.prototype.myForEach = function(callback) {
for (let i = 0; i < this.length; i++) {
callback(this[i], i, this);
}
};
๐ฏ Example:
let developers = ["Ankit", "Renil", "Krunal"];
developers.myForEach(dev => console.log(dev + " is improving!"));
// Ankit is improving!
// Renil is improving!
// Krunal is improving!
// After the massive support from each other all are improving ๐ช
๐ Mission 3: myFilter() โ "Only the Best Coders Stay in the Team For Open-Source FreeAPI!"
Not everyone makes it! Only the best coders get selected for the open-source contribution in FreeAPI peoduct. filter()
picks the best from an array.
Array.prototype.myFilter = function(callback) {
let result = [];
for (let i = 0; i < this.length; i++) {
if (callback(this[i], i, this)) {
result.push(this[i]);
}
}
return result;
};
๐ฏ Example:
let scores = [30, 50, 80, 100];
let qualified = scores.myFilter(score => score > 50); // for qualification took above 50+ that's the bar
console.log(qualified); // [80, 100] Cudo's you are qualified for contribution
๐ Mission 4: myReduce() โ "Building the Ultimate Dev Skillset!"
A great team isnโt about individualsโitโs about the combined knowledge! reduce()
takes multiple values and combines them into one.
Array.prototype.myReduce = function(callback, initialValue) {
let accumulator = initialValue;
for (let i = 0; i < this.length; i++) {
accumulator = callback(accumulator, this[i], i, this);
}
return accumulator;
};
๐ฏ Example:
let scores = [20, 60, 40, 80];
let totalScores = scores.myReduce((total, scr) => total + scr, 0);
console.log(totalScores); // 200 At the end teamwork lead's the scores ๐ฅ
๐ Mission 5: myFind() โ "Finding the Lead Developer(Superhero Dev)!"
Every dev team needs a lead developer the superhero of the team ๐ฆธโโ๏ธ! find()
searches for the first element that matches a condition.
Array.prototype.myFind = function(callback) {
for (let i = 0; i < this.length; i++) {
if (callback(this[i], i, this)) {
return this[i];
}
}
return undefined;
};
๐ฏ Example:
let developers = [
{ name: "Sujal", role: "Frontend" },
{ name: "Vaibhav", role: "Backend" },
{ name: "Renil", role: "Fullstack" }
];
let leadDev = developers.myFind(dev => dev.role === "Fullstack"); // Genius get's the lead role
console.log(leadDev); // { name: "Renil", role: "Fullstack" }
๐ฆธโโ๏ธ Mission 6: mySome() โ "Not Everyone Makes It, But the Few Heroes Will!"
Sometimes not everyone in the team is a hero, but there will always be a few champions who will make it! some()
. checks if any element in the array matches a condition.
Array.prototype.mySome = function(callback) {
for (let i = 0; i < this.length; i++) {
if (callback(this[i], i, this)) {
return true;
}
}
return false;
};
๐ฏ Example:
let heroes = [false, false, true, false];
let anyHero = heroes.mySome(hero => hero);
console.log(anyHero); // true, because one hero exists in the team ๐ฆธโโ๏ธ
โก Mission 7: myEvery() โ "Every Hero in the Team Must Be Strong!"
In a great team, every hero needs to be strong and have some unique strength. every()
checks if all elements in the array match a condition.
Array.prototype.myEvery = function(callback) {
for (let i = 0; i < this.length; i++) {
if (!callback(this[i], i, this)) {
return false;
}
}
return true;
};
๐ฏ Example:
let skilled = [true, true, true, true];
let allHeroes = skilled.myEvery(hero => hero);
console.log(allHeroes); // true, because all heroes are skilled and strong ๐ช
๐ Mission 8: myIncludes() โ "Checking for Team Members!"
In any dev team, you need to check if someone is already part of the squad. includes()
checks if an element exists in an array.
Array.prototype.myIncludes = function(value) {
for (let i = 0; i < this.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
};
๐ฏ Example:
let developers = ["Vaibhav", "Renil", "Krunal"];
let isInTeam = developers.myIncludes("Krunal");
console.log(isInTeam); // true, Krunal is part of the team!
๐ช Mission 9: mySort() โ "Sorting the Team Based on Skills!"
Every dev needs to be in the right position. sort()
helps arrange the team based on their skill levels.
Array.prototype.mySort = function(callback) {
let sortedArray = [...this];
for (let i = 0; i < sortedArray.length; i++) {
for (let j = 0; j < sortedArray.length - 1 - i; j++) {
if (callback(sortedArray[j], sortedArray[j + 1]) > 0) {
let temp = sortedArray[j];
sortedArray[j] = sortedArray[j + 1];
sortedArray[j + 1] = temp;
}
}
}
return sortedArray;
};
๐ฏ Example:
let skills = [90, 70, 50, 100];
let sortedSkills = skills.mySort((a, b) => a - b); // Sorting by skill levels
console.log(sortedSkills); // [50, 70, 90, 100]
๐ Mission 10: myConcat() โ "Uniting Powers for the Ultimate Team!"
Sometimes the team needs to combine forces with another team to grow stronger and build a true software for real world solution. concat()
is all about uniting multiple arrays into one powerful array!
Array.prototype.myConcat = function(...arrays) {
let result = [...this];
for (let array of arrays) {
result.push(...array);
}
return result;
};
๐ฏ Example:
let teamNewbie = ["Vaibhav", "Renil"];
let teamProCoders = ["Akash", "Mukul"];
let teamLegendryCoders = ["Hitesh", "Piyush"]; // The OG ones (Super Duper Heroes)
let ultimateTeam = teamNewbie.myConcat(teamProCoders, teamLegendryCoders);
console.log(ultimateTeam); // ["Vaibhav", "Renil", "Akash", "Mukul", "Hitesh", "Piyush"]
๐ Congratulations, You Are Now a JavaScript Chaicode Team Player!
๐ Mission Complete! ๐
๐ Youโve trained like a coding warrior with Hitesh & Piyush Sir, mastering powerful JavaScript methods that will make you an unstoppable force in the tech world! ๐ปโก
๐ Youโve crafted your own JavaScript methodsโjust like building your very own superpowersโready to take on any coding challenge! ๐ช๐ง
Whatโs Next?
๐ฅ Youโve leveled up, and now you are ready to take the knowledge youโve gained and apply it to build next-gen applications that will amaze your peers and clients alike! Whether you're creating a social media platform, a cutting-edge e-commerce solution, or even AI-powered software, youโve got the skills to make it happen. ๐
Time to Rise and Shine!
๐ฅ Just like the legendary developers and tech leaders you admire, now it's your time to make an impact in the coding community. Your journey has just begun, and you have everything it takes to change the world with the power of code. ๐
Take on the World with JavaScript!
Build innovative software that makes a difference. ๐ก
Create apps that people canโt live without. ๐ฑ
Keep challenging yourself to grow and learn new things. ๐ฑ
๐ฏ Mission Accomplished. Now Go Create Your Future!
๐ Build Your Dream Software (Actual Products) and make Hitesh & Piyush Sir proudโyouโve got the power, the knowledge, and the determination to succeed! ๐๐ฅ
Keep Coding, Keep Growing and Never Stop Dreaming! ๐๐