$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #32

What is the correct fix?

function findUser(id: number, users: {id: number}[]) {
  return users.find(u => u.id = id);
}
  1. Change find to filter
  2. Change id: number to id: any
  3. Change u.id = id to u.id === id
  4. Add a return type annotation
The predicate assigns instead of comparing; use ===.
Play Problem Solving ▸