BACK
PracticeInterview: windowCount() streaming batches
PRACTICE · 56 · 練

Interview: windowCount() streaming batches

Split a stream of numbers into Observable windows of 2 values and collect each window into a string.

  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, windowCount, mergeMap, toArray, map } = Rx;

const result$ = from([1, 2, 3, 4, 5]).pipe(
  windowCount(2),
  mergeMap(window$ => window$.pipe(toArray(), map(values => values.join('-'))))
);

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