Skip to content
Open
Show file tree
Hide file tree
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
65 changes: 57 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
/* Your Code Here */
const createEmployeeRecord = (employee) => {
return {
firstName: employee[0],
familyName: employee[1],
title: employee[2],
payPerHour: parseInt(employee[3], 10),
timeInEvents: [],
timeOutEvents: []
}
}

const createEmployeeRecords = (employees) => {
return employees.map(employee => createEmployeeRecord(employee))
}

function createTimeInEvent(dateStamp) {
const [date, time] = dateStamp.split(' ')
const checkIn = {
type: 'TimeIn',
hour: parseInt(time, 10),
date
}

this.timeInEvents.push(checkIn)

return this
}

function createTimeOutEvent(dateStamp) {
const [date, time] = dateStamp.split(' ')
const checkOut = {
type: 'TimeOut',
hour: parseInt(time, 10),
date
}

/*
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
sneaky bug that we'll cover in the next few lessons!
this.timeOutEvents.push(checkOut)

As a result, the lessons for this function will pass *and* it will be available
for you to use if you need it!
*/
return this
}

function hoursWorkedOnDate(dateStamp){
const checkInTime = this.timeInEvents.find(event => event.date === dateStamp).hour
const checkOutTime = this.timeOutEvents.find(event => event.date === dateStamp).hour
return (checkOutTime - checkInTime) / 100
}

function wagesEarnedOnDate(dateStamp){
return hoursWorkedOnDate.call(this, dateStamp) * this.payPerHour
}

const allWagesFor = function () {
const eligibleDates = this.timeInEvents.map(function (e) {
Expand All @@ -21,3 +61,12 @@ const allWagesFor = function () {
return payable
}

function findEmployeeByFirstName(employeeRecords, firstName){
return employeeRecords.find(employee => employee.firstName === firstName)
}

function calculatePayroll(employeeRecords){
return employeeRecords.reduce((total, employeeRecord) => {
return total + allWagesFor.call(employeeRecord)
}, 0)
}
8 changes: 4 additions & 4 deletions package-lock.json

Choose a reason for hiding this comment

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

Make sure you're checking your diff before you commit so you don't end up committing changes that you shouldn'tbe.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/indexTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ describe("The payroll system", function () {
timesOutRecordRow[1].forEach(function(timeOutStamp){
createTimeOutEvent.call(rec, timeOutStamp)
})
})
})
expect(calculatePayroll(employeeRecords)).to.eql(12480)
})
})
Expand Down