Not bad, but it could be way better.
The filter
function will help you filter out the unwanted elements from the array and return a new array consisting only of suitable items.
To work correctly, the filter
function accepts a parameter called “filtering function” or “filtering predicate”.
This “filtering function” takes a single element of the array and returns true
if the element passes the filter, otherwise it should return false
.
Let’s rewrite the previous example using the filter
function.