Skip to content

ProgrammingHero1/more-es6

Repository files navigation

simple practice problems

for you to strengthen your understanding of map, filter, forEach, and find.


🔹 Practice Problems

  1. Given an array of numbers, create a new array where each number is doubled. (use map)

  2. From an array of numbers, get only the even numbers. (use filter)

  3. From an array of numbers, find the first number that is greater than 50. (use find)

  4. Given an array of strings (names), print each name with "Hello, " in front. (use forEach)

  5. Given an array of numbers, create a new array of their squares. (use map)

  6. From an array of ages, return only the ages that are 18 or older. (use filter)

  7. From an array of numbers, find the first number that is divisible by 7. (use find)

  8. From an array of words, print the length of each word. (use forEach)

  9. Given an array of temperatures in Celsius, create a new array with the values converted to Fahrenheit. (use map)

  10. From an array of products with prices, filter out only the products that cost more than 100. (use filter)

Practice Problem with Array of Objects

I’ll give you tasks + sample arrays when needed. You’ll figure out whether to use map, filter, forEach, or find yourself.


📝 Practice Tasks

1.

const users = [
  { id: 1, name: "Alice", age: 22 },
  { id: 2, name: "Bob", age: 17 },
  { id: 3, name: "Charlie", age: 25 }
];

Task: Get only the names from the users array.


2.

const products = [
  { id: 1, name: "Laptop", price: 1200 },
  { id: 2, name: "Phone", price: 800 },
  { id: 3, name: "Pen", price: 2 }
];

Task: Return only the products that cost less than 100.


3.

const students = [
  { id: 1, name: "David", grade: "A" },
  { id: 2, name: "Eve", grade: "C" },
  { id: 3, name: "Frank", grade: "B" }
];

Task: Find the first student whose grade is "B".


4.

const books = [
  { title: "Book One", pages: 200 },
  { title: "Book Two", pages: 150 },
  { title: "Book Three", pages: 300 }
];

Task: Print each book title with its page count.


5.

const employees = [
  { id: 1, name: "Sam", salary: 5000 },
  { id: 2, name: "John", salary: 7000 },
  { id: 3, name: "Sara", salary: 4000 }
];

Task: Create a new array of employee names with their salaries increased by 10%.


6.

const cars = [
  { brand: "Toyota", year: 2018 },
  { brand: "Honda", year: 2020 },
  { brand: "Ford", year: 2015 }
];

Task: Get only the cars manufactured after 2017.


7.

const movies = [
  { id: 1, title: "Inception", rating: 8.8 },
  { id: 2, title: "The Room", rating: 3.6 },
  { id: 3, title: "Interstellar", rating: 8.6 }
];

Task: Find the first movie that has a rating below 5.


8.

const players = [
  { name: "Messi", goals: 30 },
  { name: "Ronaldo", goals: 25 },
  { name: "Neymar", goals: 20 }
];

Task: Print each player's name with the number of goals they scored.


9.

const courses = [
  { id: 1, title: "Math", completed: true },
  { id: 2, title: "English", completed: false },
  { id: 3, title: "Science", completed: true }
];

Task: Get only the titles of the courses that are completed.


10.

const orders = [
  { id: 1, total: 250 },
  { id: 2, total: 400 },
  { id: 3, total: 150 }
];

Task: Create a new array containing only the total amounts from the orders.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published