From 4dc92442e93750d7bd453eb1086a6af2adddb244 Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Mon, 3 Jun 2024 15:21:15 -0400 Subject: [PATCH 1/8] Create function for employee record --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e303d299f..81c841802 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,13 @@ -/* Your Code Here */ +function createEmployeeRecord (employeeArray) { + return { + firstName: employeeArray[0], + familyName: employeeArray[1], + title: employeeArray[2], + payPerHour: employeeArray[3], + timeInEvents: [], + timeOutEvents: [], + } +} /* We're giving you this function. Take a look at it, you might see some usage From 46ab92e1931452e4b6bf3cc99df56bbffcbeb96b Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Mon, 3 Jun 2024 15:57:40 -0400 Subject: [PATCH 2/8] Create Employees Record --- index.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 81c841802..0a2538826 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,28 @@ -function createEmployeeRecord (employeeArray) { +// employee = [ fName, lName, title, pay] +function createEmployeeRecord(employee) { return { - firstName: employeeArray[0], - familyName: employeeArray[1], - title: employeeArray[2], - payPerHour: employeeArray[3], + firstName: employee[0], + familyName: employee[1], + title: employee[2], + payPerHour: employee[3], timeInEvents: [], timeOutEvents: [], } } +employees = [ + ["moe", "sizlak", "barkeep", 2], + ["bartholomew", "simpson", "scamp", 3] +] + +// this is an array of arrays +// for each employee i want to createEmployeeRecord +// return new array with changes...map +function createEmployeeRecords(employees){ + let employeeList = employees.map((employee) => createEmployeeRecord(employee)) + return employeeList +} + + /* We're giving you this function. Take a look at it, you might see some usage From 53ee67f5110f0fa934deceb497d8f2fa4d36163d Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Tue, 4 Jun 2024 08:33:32 -0400 Subject: [PATCH 3/8] Create time in Event --- index.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0a2538826..e39153c8d 100644 --- a/index.js +++ b/index.js @@ -9,10 +9,10 @@ function createEmployeeRecord(employee) { timeOutEvents: [], } } -employees = [ - ["moe", "sizlak", "barkeep", 2], - ["bartholomew", "simpson", "scamp", 3] -] +// employees = [ +// ["moe", "sizlak", "barkeep", 2], +// ["bartholomew", "simpson", "scamp", 3] +// ] // this is an array of arrays // for each employee i want to createEmployeeRecord @@ -21,6 +21,22 @@ function createEmployeeRecords(employees){ let employeeList = employees.map((employee) => createEmployeeRecord(employee)) return employeeList } +// dateStamp = "YYYY-MM-DD HHMM" +// need to break into an array [ [YYYY-MM-DD], [HHMM]] +// destructing of string +function createTimeInEvent (dateStamp) { + let [date, time] = dateStamp.split(" ") + let clockIn = { + type: "TimeIn", + hour: parseInt(time, 10), + date: date + } + this.timeInEvents.push(clockIn) + + return this +} + + From 3a831ca9c191e63a5fe6225f3164a03a98a917fb Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Tue, 4 Jun 2024 08:36:24 -0400 Subject: [PATCH 4/8] Create time out function --- index.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e39153c8d..6af0d5d2f 100644 --- a/index.js +++ b/index.js @@ -21,9 +21,7 @@ function createEmployeeRecords(employees){ let employeeList = employees.map((employee) => createEmployeeRecord(employee)) return employeeList } -// dateStamp = "YYYY-MM-DD HHMM" -// need to break into an array [ [YYYY-MM-DD], [HHMM]] -// destructing of string + function createTimeInEvent (dateStamp) { let [date, time] = dateStamp.split(" ") let clockIn = { @@ -36,6 +34,18 @@ function createTimeInEvent (dateStamp) { return this } +function createTimeOutEvent (dateStamp) { + let [date, time] = dateStamp.split(" ") + let clockOut = { + type: "TimeOut", + hour: parseInt(time, 10), + date: date + } + this.timeOutEvents.push(clockOut) + + return this +} + From ad6638005410279af701316e916d704449a313e1 Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Tue, 4 Jun 2024 08:56:33 -0400 Subject: [PATCH 5/8] Create function for hours worked on date --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 6af0d5d2f..66c6bd7df 100644 --- a/index.js +++ b/index.js @@ -46,6 +46,13 @@ function createTimeOutEvent (dateStamp) { return this } +function hoursWorkedOnDate (enteredDate) { + let hourIn = this.timeInEvents.find((inEvent) => inEvent.date === enteredDate) + let hourOut = this.timeOutEvents.find((outEvent) => outEvent.date === enteredDate) + + return (hourOut.hour - hourIn.hour)/100 +} + From bf3e109f4448ebdfedfb1ff3e2a80d35edc35564 Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Tue, 4 Jun 2024 09:56:54 -0400 Subject: [PATCH 6/8] Create wages earned on function --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 66c6bd7df..2d1009c1d 100644 --- a/index.js +++ b/index.js @@ -47,12 +47,18 @@ function createTimeOutEvent (dateStamp) { } function hoursWorkedOnDate (enteredDate) { - let hourIn = this.timeInEvents.find((inEvent) => inEvent.date === enteredDate) - let hourOut = this.timeOutEvents.find((outEvent) => outEvent.date === enteredDate) + const hourIn = this.timeInEvents.find((inEvent) => inEvent.date === enteredDate) + const hourOut = this.timeOutEvents.find((outEvent) => outEvent.date === enteredDate) return (hourOut.hour - hourIn.hour)/100 } +function wagesEarnedOnDate (enteredDate) { + const payRate = this.payPerHour + const hoursWork = hoursWorkedOnDate.call(this, enteredDate) + + return hoursWork * payRate +} From bf48926ddeb80d7d4215680eb58d24ccfba462bc Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Tue, 4 Jun 2024 10:24:18 -0400 Subject: [PATCH 7/8] Create Payroll function --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2d1009c1d..22fc96481 100644 --- a/index.js +++ b/index.js @@ -59,10 +59,6 @@ function wagesEarnedOnDate (enteredDate) { return hoursWork * payRate } - - - - /* 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 @@ -84,3 +80,14 @@ const allWagesFor = function () { return payable } +function findEmployeeByFirstName (srcArray, firstNameString) { + // matching record or undefined (find method) + + return srcArray.find((employeeRecord) => employeeRecord.firstName = firstNameString) +} + +function calculatePayroll (employeeRecords) { + let payRoll = employeeRecords.reduce((total, employeeRecord) => total + allWagesFor.call(employeeRecord), 0) + + return payRoll +} From 190561ab075599d3fa2b8e7215951502f7f127a5 Mon Sep 17 00:00:00 2001 From: Anthony Phillips Date: Tue, 4 Jun 2024 10:28:14 -0400 Subject: [PATCH 8/8] Clean up comments and white space --- index.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/index.js b/index.js index 22fc96481..1f53749cb 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,3 @@ -// employee = [ fName, lName, title, pay] function createEmployeeRecord(employee) { return { firstName: employee[0], @@ -9,14 +8,7 @@ function createEmployeeRecord(employee) { timeOutEvents: [], } } -// employees = [ -// ["moe", "sizlak", "barkeep", 2], -// ["bartholomew", "simpson", "scamp", 3] -// ] - -// this is an array of arrays -// for each employee i want to createEmployeeRecord -// return new array with changes...map + function createEmployeeRecords(employees){ let employeeList = employees.map((employee) => createEmployeeRecord(employee)) return employeeList @@ -81,7 +73,6 @@ const allWagesFor = function () { } function findEmployeeByFirstName (srcArray, firstNameString) { - // matching record or undefined (find method) return srcArray.find((employeeRecord) => employeeRecord.firstName = firstNameString) }