Easy
Find Even Numbers Using filter Method
Description
In this challenge, you need to write a function that takes an array of numbers and returns a new array containing only the even numbers.
The filter method in JavaScript allows you to iterate over an array and return elements that meet a specified condition.
This challenge helps you understand how to filter elements based on a condition and work with numerical data.
Instructions
Write a function called filterEvenNumbers that takes one parameter:
- arr: an array of numbers.
The function should return a new array containing only the even numbers from the input array.
Example Usage
// Expected output: [2, 4, 6]filterEvenNumbers([10, 15, 20, 25]);// Expected output: [10, 20]filterEvenNumbers([7, 9, 13]);// Expected output: []
Did you know?
The first computer bug was a moth found in a Harvard Mark II computer.
Test Cases
Input:
[ 10, 15, 20, 25 ]
Expected Output:
[ 10, 20 ]