BACK
PracticeInterview: toArray() to collect a stream
PRACTICE · 15 · 練

Interview: toArray() to collect a stream

Collect the tags into an array with toArray and print them separated by a vertical bar.

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

const result$ = from(['rxjs', 'angular', 'signals']).pipe(
  toArray(),
  map(tags => tags.join('|'))
);

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