diff --git a/index.js b/index.js index e303d299..1f53749c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,56 @@ -/* Your Code Here */ +function createEmployeeRecord(employee) { + return { + firstName: employee[0], + familyName: employee[1], + title: employee[2], + payPerHour: employee[3], + timeInEvents: [], + timeOutEvents: [], + } +} + +function createEmployeeRecords(employees){ + let employeeList = employees.map((employee) => createEmployeeRecord(employee)) + return employeeList +} + +function createTimeInEvent (dateStamp) { + let [date, time] = dateStamp.split(" ") + let clockIn = { + type: "TimeIn", + hour: parseInt(time, 10), + date: date + } + this.timeInEvents.push(clockIn) + + return this +} + +function createTimeOutEvent (dateStamp) { + let [date, time] = dateStamp.split(" ") + let clockOut = { + type: "TimeOut", + hour: parseInt(time, 10), + date: date + } + this.timeOutEvents.push(clockOut) + + return this +} + +function hoursWorkedOnDate (enteredDate) { + const hourIn = this.timeInEvents.find((inEvent) => inEvent.date === enteredDate) + const hourOut = this.timeOutEvents.find((outEvent) => outEvent.date === enteredDate) + return (hourOut.hour - hourIn.hour)/100 +} + +function wagesEarnedOnDate (enteredDate) { + const payRate = this.payPerHour + const hoursWork = hoursWorkedOnDate.call(this, enteredDate) + + return hoursWork * payRate +} /* We're giving you this function. Take a look at it, you might see some usage that's new and different. That's because we're avoiding a well-known, but @@ -21,3 +72,13 @@ const allWagesFor = function () { return payable } +function findEmployeeByFirstName (srcArray, firstNameString) { + + return srcArray.find((employeeRecord) => employeeRecord.firstName = firstNameString) +} + +function calculatePayroll (employeeRecords) { + let payRoll = employeeRecords.reduce((total, employeeRecord) => total + allWagesFor.call(employeeRecord), 0) + + return payRoll +}