If the function return value is true when the function is run on that particular element, then it keeps the element.
If the function return value is false when the function is run on that particular element, then it doesn't keep the element.
After the Filter Method has been run on every element of the array it returns a new array with only the elements that it kept.
Let's start out with an array of the first 5 numbers bigger than zero.
You can see that we get the same array back.
You can see that it is a type of Array because the instanceof Array evaluated as true.
Next we need a function that will serve as our filter function.
This function, named biggerThanTwo, will take in a number as its single parameter.
The number passed into the function will then be compared to the number 2 to see if it is bigger than it.
When evaluated this will either return a true or false Boolean value.
This Boolean value is assigned to the variable booleanAnswer.
Finally, the boolean value is returned.
Let's test it out on the numbers 1, 2, 3.
We start out with the number 1.
We can see that we get false because the number 1 is not bigger than the number 2.
Next we test the number 2.
We can see that we get false because the number 2 is not bigger than the number 2.
Finally we test the number 3.
We can see that we get true because the number 3 is bigger than the number 2.
You can see the array [1, 2, 3, 4, 5].
You can see that the filter method is called off of the array.
You can see that we pass in the callback function biggerThanTwo we defined.
Important to note that we are passing in the function with the open and close parentheses.
This means that we're not running the function when we pass it in.
Finally, you can see that the result is [3, 4, 5].
Which is what we would expect as 1 and 2 are not bigger than the number 2 while 3, 4, and 5 are bigger than the number 2.
Here's the result: