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
80 changes: 71 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,64 @@
/* Your Code Here */
const createEmployeeRecord = (employeeRecord) => {
return {
firstName: employeeRecord[0],
familyName: employeeRecord[1],
title: employeeRecord[2],
payPerHour: employeeRecord[3],
timeInEvents: [],
timeOutEvents: []
};
};

/*
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!
const createEmployeeRecords = (employeeRecord) => {
return employeeRecord.map(createEmployeeRecord)
}

const createTimeInEvent = function(dateStamp) {
const splitDate = dateStamp.split(' ');
const day = splitDate[0];
const hour = parseInt(splitDate[1], 10);

const timeInEvent = {
type: "TimeIn",
date: day,
hour: hour
};

this.timeInEvents.push(timeInEvent);
return this;
};

const createTimeOutEvent = function(dateStamp) {
const splitDate = dateStamp.split(' ');
const day = splitDate[0];
const hour = parseInt(splitDate[1], 10);

const timeInEvent = {
type: "TimeOut",
date: day,
hour: hour
};

this.timeOutEvents.push(timeInEvent);
return this;
};

const hoursWorkedOnDate = function(date) {
const timeIn = this.timeInEvents.find(function (stove) {
return stove.date === date;});
const timeOut = this.timeOutEvents.find(function (stove) {
return stove.date === date;});

return (timeOut.hour - timeIn.hour) / 100;
};
window.hoursWorkedOnDate = hoursWorkedOnDate;

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

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

const allWagesFor = function () {
const eligibleDates = this.timeInEvents.map(function (e) {
Expand All @@ -16,8 +67,19 @@ const allWagesFor = function () {

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!
}.bind(this), 0)

return payable
}

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

const calculatePayroll = (employeeRecords) => {
return employeeRecords.reduce((total, employee) => {
return total + allWagesFor.call(employee);
}, 0);
};
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A JavaScript lab",
"main": "index.js",
"scripts": {
"test": "mocha --timeout 5000 -R mocha-multi --reporter-options spec=-,json=.results.json"
"test": "mocha --timeout 5000 -R mocha-multi --reporter-options spec=-,json=.results.json -b"
},
"author": "flatironschool",
"license": "Included in Repo",
Expand Down