Build Your Own JavaScript Methods with Hitesh & Piyush's Dev Team! ๐Ÿš€

Build Your Own JavaScript Methods with Hitesh & Piyush's Dev Team! ๐Ÿš€

ยท

7 min read

๐ŸŒŸ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! ๐ŸŒŸ๐Ÿ†

ย