Skip to content

Instantly share code, notes, and snippets.

@iamsaief
Created August 22, 2020 10:33
Show Gist options
  • Save iamsaief/b5d2b3944ee5e9ff54df564dd3cdf7ad to your computer and use it in GitHub Desktop.
Save iamsaief/b5d2b3944ee5e9ff54df564dd3cdf7ad to your computer and use it in GitHub Desktop.
/* Map */
const numbers = [2, 3, 4, 5, 6, 8];
const squaredNum = numbers.map((num) => num * num);
console.log(squaredNum);
// Output : [ 4, 9, 16, 25, 36, 64 ]
/* Filter */
const shapes = ["🟨", "🟩", "πŸ”΅", "πŸ”΄", "🟨", "🟩", "πŸ”΅", "πŸ”΄"];
const circle = shapes.filter((item) => item === "πŸ”΄");
const square = shapes.filter((item) => item === "🟩");
console.log(circle);
console.log(square);
// Output : ["πŸ”΄", "πŸ”΄"]
// Output : ["🟩", "🟩"]
/* Find */
const hearts = ["πŸ’™", "πŸ’›", "🧑", "πŸ’š", "πŸ’œ"];
const greenH = hearts.find((item) => item === "πŸ’š");
console.log(greenH);
// Output : πŸ’š
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment