Code Lab

Modo entrevista. Cronômetro de 6 min, sem dicas e sem autocompletar

Employees

FácilClasses6 min

Write a class Employee. The constructor new Employee(name, age, empId) stores the fields name, age and empId. The method info() returns a string like 'Ann, 30, id 101'.

Also write a function findEmployee(employees, empId). It looks for the employee with that empId in the array and returns it. If there is none, return null.

Exemplos

new Employee('Ann', 30, 101).info()

Retorna 'Ann, 30, id 101'

findEmployee([new Employee('Ann', 30, 101), new Employee('Bob', 41, 102)], 102).info()

Retorna 'Bob, 41, id 102'

findEmployee([new Employee('Ann', 30, 101)], 7)

Retorna null

Cobrada em Cognizant · Fonte

Carregando o editor...
  1. The constructor stores the fields
  2. info() format
  3. The search finds the employee
  4. No employee gives null

Os testes ocultos rodam no envio