Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +13 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let employeeList = employees.map((employee) => createEmployeeRecord(employee))
return employeeList
return employees.map((employee) => createEmployeeRecord(employee))

}

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
Expand All @@ -21,3 +72,13 @@ const allWagesFor = function () {
return payable
}

function findEmployeeByFirstName (srcArray, firstNameString) {

return srcArray.find((employeeRecord) => employeeRecord.firstName = firstNameString)
Comment on lines +76 to +77

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return srcArray.find((employeeRecord) => employeeRecord.firstName = firstNameString)
return srcArray.find((employeeRecord) => employeeRecord.firstName = firstNameString)

}

function calculatePayroll (employeeRecords) {
let payRoll = employeeRecords.reduce((total, employeeRecord) => total + allWagesFor.call(employeeRecord), 0)

return payRoll
Comment on lines +81 to +83

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let payRoll = employeeRecords.reduce((total, employeeRecord) => total + allWagesFor.call(employeeRecord), 0)
return payRoll
return employeeRecords.reduce((total, employeeRecord) => total + allWagesFor.call(employeeRecord), 0)

}