Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Context Lab Using This Keyword #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
54 changes: 52 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
/* Your Code Here */
const createEmployeeRecord = (employee) => {
return {
firstName: employee[0],
familyName: employee[1],
title: employee[2],
payPerHour: employee[3],
timeInEvents: [],
timeOutEvents: [],
}
}

const createEmployeeRecords = (records) => records.map(record => createEmployeeRecord(record))

const createTimeInEvent = function(dateStamp){
this.timeInEvents.push({
type: "TimeIn",
date: dateStamp.slice(0,10),
hour: parseInt(dateStamp.slice(-4))
})
return this
}

const createTimeOutEvent = function(dateStamp){
this.timeOutEvents.push({
type: "TimeOut",
date: dateStamp.slice(0,10),
hour: parseInt(dateStamp.slice(-4))
})
return this
}

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

const wagesEarnedOnDate = function(date){
const hoursWorked = hoursWorkedOnDate.call(this, date)
return hoursWorked * this.payPerHour
}

const findEmployeeByFirstName = function(emps, empToFind){
return emps.find(emp => emp.firstName === empToFind)
}

function calculatePayroll(employeeRecords){
return employeeRecords.map(emp => allWagesFor.call(emp)).reduce((acc, wages) => acc + wages)
}


/*
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 @@ -9,7 +59,8 @@
for you to use if you need it!
*/

const allWagesFor = function () {
function allWagesFor() {
// console.log(this)

Choose a reason for hiding this comment

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

Suggested change
// console.log(this)

const eligibleDates = this.timeInEvents.map(function (e) {
return e.date
})
Expand All @@ -20,4 +71,3 @@ const allWagesFor = function () {

return payable
}