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
103 changes: 88 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,96 @@
/* Your Code Here */
function createEmployeeRecord(array) {
const [firstName, familyName, title, payPerHour] = array;

/*
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!
return {
firstName: firstName,
familyName: familyName,
title: title,
payPerHour: payPerHour,
timeInEvents: [],
timeOutEvents: [],
createTimeInEvent: createTimeInEvent,
createTimeOutEvent: createTimeOutEvent,
hoursWorkedOnDate: hoursWorkedOnDate,
wagesEarnedOnDate: wagesEarnedOnDate,
};
}

function createEmployeeRecords(arrays) {
const employeeRecords = [];
for (const array of arrays) {
employeeRecords.push(createEmployeeRecord(array))
}
return employeeRecords;
}

function createTimeEvent(eventType, dateStamp) {
const [date, hour] = dateStamp.split(" ");

return {
type: eventType,
hour: parseInt(hour),
date: date,
}
}

function createTimeInEvent(dateStamp) {
const timeInEvent = createTimeEvent("TimeIn", dateStamp);
this.timeInEvents.push(timeInEvent);
return this;
}

function createTimeOutEvent(dateStamp) {
const timeOutEvent = createTimeEvent("TimeOut", dateStamp);
this.timeOutEvents.push(timeOutEvent);
return this;
}

As a result, the lessons for this function will pass *and* it will be available
for you to use if you need it!
*/
function hoursWorkedOnDate(date) {
const findDate = array => {
let dateMatch;
for (const obj of array) {
if (obj.date === date) {
dateMatch = obj;
}
}
return dateMatch;
}

const timeIn = findDate(this.timeInEvents).hour;
const timeOut = findDate(this.timeOutEvents).hour;

return (timeOut - timeIn) / 100;
}

function wagesEarnedOnDate(date) {
return this.hoursWorkedOnDate(date) * this.payPerHour;
}

const allWagesFor = function () {
const eligibleDates = this.timeInEvents.map(function (e) {
return e.date
})
const eligibleDates = this.timeInEvents.map(function (e) {
return e.date;
});

const payable = eligibleDates.reduce(function (memo, d) {
return memo + wagesEarnedOnDate.call(this, d)
}.bind(this), 0) // <== Hm, why did we need to add bind() there? We'll discuss soon!
const payable = eligibleDates.reduce(
function (memo, d) {
return memo + wagesEarnedOnDate.call(this, d);
}.bind(this),
0
); // <== Hm, why did we need to add bind() there? We'll discuss soon!

return payable
return payable;
};

function findEmployeeByFirstName(srcArray, firstName) {
return srcArray.find((record) => record.firstName === firstName);
}

function calculatePayroll(srcArray) {
let payroll = 0;

for (const record of srcArray) {
payroll += allWagesFor.call(record);
}

return payroll;
}
8 changes: 4 additions & 4 deletions package-lock.json

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