Javascript exercise
1.Write a function that takes an array of numbers and returns a new array containing only the
even numbers.
Example:
Input: [1, 2, 3, 4, 5, 6]
Output: [2, 4, 6]
2.Write a function that accepts a JavaScript Date object and returns the day of the week as a
string (e.g., "Monday").
Example:
Input: new Date("2025-06-10")
Output: "Tuesday"
3.Write a function that accepts a Map object and returns an array of all its keys.
Example:
Input: new Map([["name", "John"], ["age", 30]])
Output: ["name", "age"]
4.Create a class named Car that has a method drive() which logs "The car is driving" to the
console. Instantiate the class and call the drive() method.
5.Use an arrow function with the .map() method to convert an array of numbers into their
squares.
Example:
Input: [2, 3, 4]
Output: [4, 9, 16]
6.Create a class Animal with a method makeSound(). Then create a subclass Dog that calls
makeSound() using super and adds its own message like "The dog barks."
7.Write an arrow function that returns an object with keys name and age from parameters.
Example:
Input: ("Alice", 25)
Output: { name: "Alice", age: 25 }
8.Given an array of numbers, write a function using filter() and map() to return the squares of
only the even numbers.
Example:
Input: [1, 2, 3, 4]
Output: [4, 16]
9.Write a function that flattens a nested array (one level deep).
Example:
Input: [1, [2, 3], 4, [5]]
Output: [1, 2, 3, 4, 5]
10.Write a function that returns an array of duplicate elements from the input array.
Example:
Input: [1, 2, 3, 2, 4, 5, 1]
Output: [1, 2]
11.Use reduce() to sum all numbers in an array.
Example:
Input: [10, 20, 30]
Output: 60