Integers Greater Than

Easy Important

Prompt

Given a set of integers arr, return a new array of those integers greater than n.

Playground

Hint

The filter method is a built-in array method in JavaScript that creates a new array with all elements that pass the test implemented by the provided function. This is a perfect fit for the problem at hand, where we need to create a new array containing only the integers greater than n.

Solution

Explanation

  • The function uses the filter method on the arr array.
  • The filter method creates a new array with only the elements from arr that pass a certain condition.
  • The condition is defined by an arrow function: (num) => num > n.
  • This arrow function checks if each number num in the arr array is greater than n.
  • If num is greater than n, it is included in the new filtered array.
  • If num is not greater than n, it is excluded from the new filtered array.
  • The new filtered array is returned by the integersGreaterThan function.

So, in simple terms, the integersGreaterThan function takes a number and an array, and returns a new array containing only the elements from the original array that are greater than the given number.

00:00