BACK
PracticeInterview: find() the first admin
PRACTICE · 18 · 練

Interview: find() the first admin

Find the first user with role === "admin" and output their name.

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

const users = [
  { name: 'Mia', role: 'user' },
  { name: 'Sam', role: 'admin' },
  { name: 'Lee', role: 'admin' },
];

const result$ = from(users).pipe(
  find(user => user.role === 'admin'),
  map(user => user.name)
);

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