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
9 changes: 9 additions & 0 deletions code_explanation
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## createEmployeeRecords
`map()` iterates through the container array
ex employees[
["moe", "sizlak", "barkeep", 2],
["bartholomew", "simpson", "scamp", 3]
["Mister", "Matt", "Chief Awesomeness Offiser", 1000]
]

- calling the createEmployeeRecord converts the nested arrays into objects
95 changes: 87 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,92 @@
/* Your Code Here */

/*
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!

As a result, the lessons for this function will pass *and* it will be available
for you to use if you need it!
*/
//converts an array with employee record to an object
let employee1 = ["Gray", "Worm", "Security", 1]
function createEmployeeRecord(employee){
// employee= ["moe", "sizlak", "barkeep", 2]
const employeeRecord={
firstName:employee[0],
familyName:employee[1],
title:employee[2],
payPerHour:employee[3],
timeInEvents:[],
timeOutEvents:[]
}
return employeeRecord;
}
createEmployeeRecord(employee1)



let employees=[
["bartholomew", "simpson", "scamp",2],
["Mister", "Matt", "Chief Awesomeness Offiser",3]
]

// converts multiple arrays that are nested inside a parent array
//into objects similar to the employeeRecord
const createEmployeeRecords=(employeesContainerArray)=>{
let employeeRecords=employeesContainerArray.map(employee=>createEmployeeRecord(employee))
return employeeRecords;
}
createEmployeeRecords(employees)



//"it adds a timeIn event Object to an employee's record of timeInEvents when
//provided an employee record and Date/Time String and returns the updated record"
let createTimeInEvent = function(dateStamp){

this.timeInEvents.push({
type: "TimeIn",
hour: Number.parseInt(dateStamp.slice(11)),
date: dateStamp.slice(0, 10)
})

return this
}

let createTimeOutEvent = function(dateStamp){

this.timeOutEvents.push({
type: "TimeOut",
hour: Number.parseInt(dateStamp.slice(11)),
date: dateStamp.slice(0, 10)
})

return this
}

let hoursWorkedOnDate = function(soughtDate){
let comingIn = this.timeInEvents.find(function(e){
return e.date === soughtDate
})

let goingOut = this.timeOutEvents.find(function(e){
return e.date === soughtDate
})

return (goingOut.hour - comingIn.hour) / 100
}

let wagesEarnedOnDate = function(dateSought){
let rawWage = hoursWorkedOnDate.call(this, dateSought)
* this.payPerHour
return parseFloat(rawWage.toString())
}

let findEmployeeByFirstName = function(srcArray, firstName) {
return srcArray.find(function(rec){
return rec.firstName === firstName
})
}

let calculatePayroll = function(arrayOfEmployeeRecords){
return arrayOfEmployeeRecords.reduce(function(memo, rec){
return memo + allWagesFor.call(rec)
}, 0)
}


const allWagesFor = function () {
const eligibleDates = this.timeInEvents.map(function (e) {
Expand Down
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.