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 thearr
array. - The
filter
method creates a new array with only the elements fromarr
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 thearr
array is greater thann
. - If
num
is greater thann
, it is included in the new filtered array. - If
num
is not greater thann
, 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