From 2b060714798f91a140403756490d7082d65948bc Mon Sep 17 00:00:00 2001 From: Brian Wangila Date: Fri, 24 Jun 2022 23:35:59 +0300 Subject: [PATCH 1/2] assignment almost finished --- index.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 10 +++--- package.json | 2 +- 3 files changed, 91 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index e303d299..a51e71d8 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,90 @@ /* Your Code Here */ +const createEmployeeRecord = (array) => { + return { + firstName: array[0], + familyName: array[1], + title: array[2], + payPerHour: array[3], + timeInEvents: [], + timeOutEvents: [], + } + + } + + const createEmployeeRecords = (employeeRecords) => { + return employeeRecords.map(arrayEmp => { + return createEmployeeRecord(arrayEmp) + }) + } + + const timeCalc = (dateTime) => { + return parseInt(dateTime.match(/\d{4}$/)[0]) + } + + const dateCalc = (dateTime) => { + return dateTime.match(/\d{4}-\d{2}-\d{2}/)[0] + } + + const createTimeInEvent = (timeIn) => { + this.timeInEvents.push({ + type: "TimeIn", + date: dateCalc(timeIn), + hour: timeCalc(timeIn) + + }) + return this + } + + + const createTimeOutEvent = (timeOut) => { + this.timeOutEvents.push({ + type: "TimeOut", + date: dateCalc(timeOut), + hour: timeCalc(timeOut) + + }) + return this + } + + + const hoursWorkedOnDate = (dateCalc) => { + const timeIn = this.timeInEvents.find((event) => { + event.date == dateCalc + + }) + + const timeOut = this.timeOutEvents.find((event) => { + event.date == dateCalc + }) + + const timeWorked = (timeOut.hour - timeIn.hour) / 100 + return timeWorked + + } + + + const wagesEarnedOnDate = (date) => { + const wagesEarned = hoursWorkedOnDate.call(this, dateCalc) + const realWage = wagesEarned * this.payPerHour + return realWage + + } + + + const findEmployeeByFirstName = (employees, firstName) => { + return employees.find(employee => employee.firstName === firstName) + } + + + + const calculatePayroll = (employeeRecord) => { + return employeeRecord.reduce((total, employee) => { + return total + allWagesFor.call(employee) + }, 0) + + } + /* 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 diff --git a/package-lock.json b/package-lock.json index 13ee0eee..b67156a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "chai": "4.1.2", "file-system": "2.2.2", "jsdom": "9.2.1", - "mocha": "5.2.0", + "mocha": "^5.2.0", "mocha-jsdom": "~1.1.0", "mocha-multi": "1.0.1" } @@ -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..2f39722e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "chai": "4.1.2", "file-system": "2.2.2", "jsdom": "9.2.1", - "mocha": "5.2.0", + "mocha": "^5.2.0", "mocha-jsdom": "~1.1.0", "mocha-multi": "1.0.1" }, From ec8848cfa15e21052df356a79f60480915e8a3cd Mon Sep 17 00:00:00 2001 From: Brian Wangila Date: Fri, 8 Jul 2022 14:05:36 +0300 Subject: [PATCH 2/2] commit tree 347d2d1805b51a2005550f471744a9dbaf8ba704 --- index.js | 62 ++++++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/index.js b/index.js index a51e71d8..387d33af 100644 --- a/index.js +++ b/index.js @@ -1,62 +1,56 @@ /* Your Code Here */ const createEmployeeRecord = (array) => { - return { - firstName: array[0], - familyName: array[1], - title: array[2], - payPerHour: array[3], - timeInEvents: [], - timeOutEvents: [], - } - + return { + firstName: array[0], + familyName: array[1], + title: array[2], + payPerHour: array[3], + timeInEvents: [], + timeOutEvents: [], } +} + const createEmployeeRecords = (employeeRecords) => { return employeeRecords.map(arrayEmp => { return createEmployeeRecord(arrayEmp) }) } - const timeCalc = (dateTime) => { - return parseInt(dateTime.match(/\d{4}$/)[0]) - } - const dateCalc = (dateTime) => { - return dateTime.match(/\d{4}-\d{2}-\d{2}/)[0] - } + function createTimeInEvent(dateStamp){ + const [date, hour] = dateStamp.split(" ") - const createTimeInEvent = (timeIn) => { this.timeInEvents.push({ type: "TimeIn", - date: dateCalc(timeIn), - hour: timeCalc(timeIn) + hour: parseInt(hour, 10), + date, }) return this } - const createTimeOutEvent = (timeOut) => { + function createTimeOutEvent(dateStamp){ + const [date, hour] = dateStamp.split(" ") + this.timeOutEvents.push({ type: "TimeOut", - date: dateCalc(timeOut), - hour: timeCalc(timeOut) + hour: parseInt(hour, 10), + date, }) return this } - const hoursWorkedOnDate = (dateCalc) => { - const timeIn = this.timeInEvents.find((event) => { - event.date == dateCalc + function hoursWorkedOnDate (dates) { + const timeIn = this.timeInEvents.find(event => + event.date === dates) - }) - - const timeOut = this.timeOutEvents.find((event) => { - event.date == dateCalc - }) + const timeOut = this.timeOutEvents.find(event => + event.date === dates) const timeWorked = (timeOut.hour - timeIn.hour) / 100 return timeWorked @@ -64,10 +58,10 @@ const createEmployeeRecord = (array) => { } - const wagesEarnedOnDate = (date) => { - const wagesEarned = hoursWorkedOnDate.call(this, dateCalc) - const realWage = wagesEarned * this.payPerHour - return realWage + function wagesEarnedOnDate (date) { + const timeWorked = hoursWorkedOnDate.call(this, date) + return timeWorked * this.payPerHour + // return realWage } @@ -85,6 +79,8 @@ const createEmployeeRecord = (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