The filter operator helps you pick only the data you want from a stream of values. It works like a sieve, letting through only items that match your rule.
When you want to react only to certain user actions, like clicks on a specific button.
When you receive many events but need to process only those with a certain property.
When working with data streams and you want to ignore unwanted values.
When you want to simplify your code by handling only relevant data.
When you want to avoid extra work by skipping unnecessary events.
A. The filter callback does not return false for odd numbers.
B. The filter operator is used outside pipe.
C. The subscribe method is missing.
D. The filter callback should return a number, not boolean.
Solution
Step 1: Analyze the filter callback function
The callback returns true for even numbers but returns undefined (no return) for odd numbers.
Step 2: Understand filter expects boolean return
Filter needs true or false; undefined is treated as false but is unclear and error-prone.
Final Answer:
The filter callback does not return false for odd numbers. -> Option A
Quick Check:
Filter callback must return true or false explicitly [OK]
Hint: Always return true or false in filter callback [OK]
Common Mistakes:
Missing explicit false return in filter
Using filter outside pipe
Confusing filter callback return types
5. You want to filter a stream of user objects to only those who are active and have age over 18. Which filter function correctly applies both conditions inside pipe()?
users$.pipe(
filter( /* your code here */ )
).subscribe(activeAdults => console.log(activeAdults));
hard
A. user => user.isActive && user.age >= 18
B. user => user.isActive || user.age > 18
C. user => user.isActive && user.age > 18 && user.name
D. user => user.isActive && user.age > 18
Solution
Step 1: Understand the conditions
We want users who are active AND older than 18 (strictly greater).
Step 2: Check each option's logic
user => user.isActive && user.age > 18 uses && with user.isActive and user.age > 18, matching requirements exactly.
Final Answer:
user => user.isActive && user.age > 18 -> Option D
Quick Check:
Both conditions true with AND operator [OK]
Hint: Use && to combine multiple filter conditions [OK]
Common Mistakes:
Using || instead of && to combine conditions
Using >= instead of > if strict condition needed
Adding unrelated conditions like user.name
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.