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

// Function to create employee records from an array of arrays
function createEmployeeRecords(arrays) {
  return arrays.map(array => createEmployeeRecord(...array));
}

// Function to record time in for an employee
function createTimeInEvent(employee, timeStamp) {
  employee.timeInEvents.push({
    type: "TimeIn",
    hour: parseInt(timeStamp.slice(11, 13)),
    date: timeStamp.slice(0, 10)
  });
  return employee;
}

// Function to record time out for an employee
function createTimeOutEvent(employee, timeStamp) {
  employee.timeOutEvents.push({
    type: "TimeOut",
    hour: parseInt(timeStamp.slice(11, 13)),
    date: timeStamp.slice(0, 10)
  });
  return employee;
}

// Function to calculate hours worked on a specific date
function hoursWorkedOnDate(employee, date) {
  const timeIn = employee.timeInEvents.find(event => event.date === date);
  const timeOut = employee.timeOutEvents.find(event => event.date === date);
  return (timeOut.hour - timeIn.hour) / 100;
}

// Function to calculate wages earned on a specific date
function wagesEarnedOnDate(employee, date) {
  const hoursWorked = hoursWorkedOnDate(employee, date);
  return hoursWorked * employee.payPerHour;
}

// Function to calculate all wages for an employee
function allWagesFor(employee) {
  const datesWorked = employee.timeInEvents.map(event => event.date);
  return datesWorked.reduce((totalWages, date) => totalWages + wagesEarnedOnDate(employee, date), 0);
}

// Function to find an employee by first name
function findEmployeeByFirstName(srcArray, firstName) {
  return srcArray.find(employee => employee.firstName === firstName);
}

// Function to calculate payroll for all employees
function calculatePayroll(employees) {
  return employees.reduce((totalPayroll, employee) => totalPayroll + allWagesFor(employee), 0);
}