BACK
PracticeReal-life: distinct() to dedupe users
PRACTICE · 54 · 練

Real-life: distinct() to dedupe users

Keep only the first user for each id and output the names.

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

const users = [
  { id: 1, name: 'Ana' },
  { id: 1, name: 'Ana copy' },
  { id: 2, name: 'Bo' },
];

const result$ = from(users).pipe(
  distinct(user => user.id),
  map(user => user.name)
);

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