diff --git a/index.js b/index.js index e303d299..dc5fdab3 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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); +}; diff --git a/package-lock.json b/package-lock.json index 13ee0eee..b369d8bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3177,7 +3177,7 @@ "dependencies": { "combined-stream": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", + "resolved": "http://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", "integrity": "sha1-cj599ugBrFYTETp+RFqbactjKBg=", "dev": true, "requires": { @@ -3442,9 +3442,9 @@ } }, "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", "dev": true }, "lodash.once": { diff --git a/package.json b/package.json index dc887287..4e1113f2 100644 --- a/package.json +++ b/package.json @@ -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",