Bird
0
0

How can you combine map with filter to emit only doubled even numbers from an observable emitting 1 to 5?

hard🚀 Application Q9 of 15
Angular - RxJS Operators
How can you combine map with filter to emit only doubled even numbers from an observable emitting 1 to 5?
Asource$.pipe(filter(x => x % 2 === 0), map(x => x * 2))
Bsource$.pipe(map(x => x * 2), filter(x => x % 2 === 0))
Csource$.pipe(map(x => x % 2 === 0), filter(x => x * 2))
Dsource$.pipe(filter(x => x * 2), map(x => x % 2 === 0))
Step-by-Step Solution
Solution:
  1. Step 1: Filter even numbers first

    Use filter(x => x % 2 === 0) to keep only even numbers (2 and 4).
  2. Step 2: Then double the filtered numbers

    Apply map(x => x * 2) to double the filtered values, resulting in 4 and 8.
  3. Final Answer:

    source$.pipe(filter(x => x % 2 === 0), map(x => x * 2)) -> Option A
  4. Quick Check:

    Filter then map for even doubled numbers = source$.pipe(filter(x => x % 2 === 0), map(x => x * 2)) [OK]
Quick Trick: Filter first, then map for correct sequence [OK]
Common Mistakes:
MISTAKES
  • Mapping before filtering
  • Swapping filter and map logic
  • Using wrong conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes