BACK
PracticeInterview: filter() active tickets
PRACTICE · 04 · 練

Interview: filter() active tickets

From a stream of tickets, keep only status === "open" and log their ids.

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

const tickets = [
  { id: 'T1', status: 'open' },
  { id: 'T2', status: 'closed' },
  { id: 'T3', status: 'open' },
];

const result$ = from(tickets).pipe(
  filter(ticket => ticket.status === 'open'),
  map(ticket => ticket.id)
);

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