BACK
PracticeInterview: partition() to split a stream
PRACTICE · 43 · 練

Interview: partition() to split a stream

Split a stream of numbers into even$ and odd$ with the top-level partition.

  1. Solve the task in the editor — no long theory.
  2. Run the check and compare your output with the expected result.
  3. Stuck? Open the solution and carry the approach into your own code.
Solution spoiler · click to reveal
const { from, partition } = Rx;

const source$ = from([1, 2, 3]);

const [even$, odd$] = partition(source$, value => value % 2 === 0);

even$.subscribe(value => console.log('even:' + value));
odd$.subscribe(value => console.log('odd:' + value));
script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...