fork download
  1. // Function to create an employee record
  2. function createEmployeeRecord(employeeData) {
  3. const [firstName, familyName, title, payPerHour] = employeeData;
  4. return {
  5. firstName,
  6. familyName,
  7. title,
  8. payPerHour,
  9. timeInEvents: [],
  10. timeOutEvents: []
  11. };
  12. }
  13.  
  14. // Function to create employee records for multiple employees
  15. function createEmployeeRecords(employeesData) {
  16. return employeesData.map(createEmployeeRecord);
  17. }
  18.  
  19. // Function to record an employee's clock-in time
  20. function createTimeInEvent(employee, timeStamp) {
  21. if (!employee.timeInEvents) employee.timeInEvents = []; // Check if timeInEvents array exists
  22. employee.timeInEvents.push({
  23. type: "TimeIn",
  24. hour: parseInt(timeStamp.slice(11, 13)),
  25. date: timeStamp.slice(0, 10)
  26. });
  27. return employee;
  28. }
  29.  
  30. // Function to record an employee's clock-out time
  31. function createTimeOutEvent(employeeRecord, dateTime) {
  32. if (!dateTime) return employeeRecord; // Check if dateTime is provided
  33. const [date, hour] = dateTime.split(' ');
  34. employeeRecord.timeOutEvents.push({
  35. type: "TimeOut",
  36. hour: parseInt(hour, 10),
  37. });
  38. return employeeRecord;
  39. }
  40.  
  41. // Function to calculate hours worked by an employee on a specific date
  42. function hoursWorkedOnDate(employeeRecord, date) {
  43. const timeInEvent = employeeRecord.timeInEvents.find(event => event.date === date);
  44. const timeOutEvent = employeeRecord.timeOutEvents.find(event => event.date === date);
  45. return (timeOutEvent.hour - timeInEvent.hour) / 100;
  46. }
  47.  
  48. // Function to calculate wages earned by an employee on a specific date
  49. function wagesEarnedOnDate(employeeRecord, date) {
  50. const hoursWorked = hoursWorkedOnDate(employeeRecord, date);
  51. return hoursWorked * employeeRecord.payPerHour;
  52. }
  53.  
  54. // Function to calculate total wages earned by an employee for all dates
  55. function allWagesFor(employeeRecord) {
  56. return employeeRecord.timeInEvents.reduce((totalWages, event) => totalWages + wagesEarnedOnDate(employeeRecord, event.date), 0);
  57. }
  58.  
  59. // Function to find an employee record by first name
  60. function findEmployeeByFirstName(employeesArray, firstName) {
  61. return employeesArray.find(employee => employee.firstName === firstName);
  62. }
  63.  
  64. // Function to calculate total payroll for all employees
  65. function calculatePayroll(employeesArray) {
  66. return employeesArray.reduce((totalPayroll, employee) => totalPayroll + allWagesFor(employee), 0);
  67. }
  68.  
  69.  
Success #stdin #stdout 0.02s 25840KB
stdin
Standard input is empty
stdout
// Function to create an employee record
function createEmployeeRecord(employeeData) {
    const [firstName, familyName, title, payPerHour] = employeeData;
    return {
      firstName,
      familyName,
      title,
      payPerHour,
      timeInEvents: [],
      timeOutEvents: []
    };
  }
  
  // Function to create employee records for multiple employees
  function createEmployeeRecords(employeesData) {
    return employeesData.map(createEmployeeRecord);
  }
  
  // Function to record an employee's clock-in time
  function createTimeInEvent(employee, timeStamp) {
    if (!employee.timeInEvents) employee.timeInEvents = []; // Check if timeInEvents array exists
    employee.timeInEvents.push({
      type: "TimeIn",
      hour: parseInt(timeStamp.slice(11, 13)),
      date: timeStamp.slice(0, 10)
    });
    return employee;
  }
  
  // Function to record an employee's clock-out time
  function createTimeOutEvent(employeeRecord, dateTime) {
    if (!dateTime) return employeeRecord; // Check if dateTime is provided
    const [date, hour] = dateTime.split(' ');
    employeeRecord.timeOutEvents.push({
      type: "TimeOut",
      hour: parseInt(hour, 10),
      date
    });
    return employeeRecord;
  }
  
  // Function to calculate hours worked by an employee on a specific date
  function hoursWorkedOnDate(employeeRecord, date) {
    const timeInEvent = employeeRecord.timeInEvents.find(event => event.date === date);
    const timeOutEvent = employeeRecord.timeOutEvents.find(event => event.date === date);
    return (timeOutEvent.hour - timeInEvent.hour) / 100;
  }
  
  // Function to calculate wages earned by an employee on a specific date
  function wagesEarnedOnDate(employeeRecord, date) {
    const hoursWorked = hoursWorkedOnDate(employeeRecord, date);
    return hoursWorked * employeeRecord.payPerHour;
  }
  
  // Function to calculate total wages earned by an employee for all dates
  function allWagesFor(employeeRecord) {
    return employeeRecord.timeInEvents.reduce((totalWages, event) => totalWages + wagesEarnedOnDate(employeeRecord, event.date), 0);
  }
  
  // Function to find an employee record by first name
  function findEmployeeByFirstName(employeesArray, firstName) {
    return employeesArray.find(employee => employee.firstName === firstName);
  }
  
  // Function to calculate total payroll for all employees
  function calculatePayroll(employeesArray) {
    return employeesArray.reduce((totalPayroll, employee) => totalPayroll + allWagesFor(employee), 0);
  }