Easy

Filter Elements in an Array

Description

In this challenge, you need to write a function that takes an array of numbers and a threshold value as input.

The function should return a new array containing only the numbers that are greater than the given threshold.

The filter method is a built-in JavaScript function that creates a new array with elements that pass a specified condition. Understanding how to use filter is essential for processing and manipulating data effectively.

Instructions

Write a function called filterGreaterThan that takes two parameters: arr - an array of numbers. threshold - a number to compare each element against.

The function should return a new array containing numbers greater than the threshold.

Example Usage

filterGreaterThan([10, 25, 5, 8, 30], 10);
// Expected output: [25, 30]
filterGreaterThan([1, 2, 3, 4, 5], 3);
// Expected output: [4, 5]

window code 2Test Cases

Input:

[
  1,
  2,
  3,
  4,
  5
]

Expected Output:

[
  4,
  5
]