Using childcare schools - I have two arrays that I need to match on 2 columns of each array:
Attendance by Department: [date, dept, attended]
0: (3) ["09-30-2019", "00_Infants", 22]
1: (3) ["09-30-2019", "01_Ones", 38]
2: (3) ["09-30-2019", "02_Twos", 40]
3: (3) ["09-30-2019", "03_Threes", 42]
4: (3) ["09-30-2019", "04_Fours", 19]
5: (3) ["10-01-2019", "00_Infants", 27]
6: (3) ["10-01-2019", "01_Ones", 42]
7: (3) ["10-01-2019", "02_Twos", 51]
ETC...
Expense by Department [date, dept, expense]
0: (3) ["09-30-2019", "00_Infants", "584.56"]
1: (3) ["09-30-2019", "01_Ones", "701.51"]
2: (3) ["09-30-2019", "02_Twos", "614.02"]
3: (3) ["09-30-2019", "03_Threes", "442.50"]
4: (3) ["09-30-2019", "04_Fours", "166.65"]
5: (3) ["09-30-2019", "06_Floater", "141.37"]
6: (3) ["09-30-2019", "07_Office", "246.91"]
7: (3) ["09-30-2019", "08_Administration", "0.00"]
8: (3) ["09-30-2019", "09_Director", "0.00"]
9: (3) ["09-30-2019", "12_Kitchen", "0.00"]
10: (3) ["10-01-2019", "00_Infants", "760.37"]
11: (3) ["10-01-2019", "01_Ones", "756.48"]
12: (3) ["10-01-2019", "02_Twos", "640.23"]
13: (3) ["10-01-2019", "03_Threes", "552.66"]
--
I want to match Expense.date && Expense.department to Attendance.date && Attendance.department ONLY where .department appears in Attendance[] THEN, append Expense.expense to the matched record in Attendance
I've tried mapping, filtering, d3.js nest(), Object.assign(), ifs, $.each...
Here is the really bad last things I haven't deleted and started over from scratch - I understand it alone looks awful and not close; however, SO wanted code.
let ffs = attended.map(function (x, i) {
return {
"date": emp[x],
"other": emp[i][0]
}
}.bind(this));
let mfer = attended.map(x => Object.assign(x, emp.find(y => y[0] === x[0])));
Expected results: [date, department, attended, expense]
0: (3) ["09-30-2019", "00_Infants", 22, 584.56]
1: (3) ["09-30-2019", "01_Ones", 38, 701.51]
2: (3) ["09-30-2019", "02_Twos", 40, 613.02]
Actual results: anything and everything but.
My browser search history shows 115 relevant queries between 19:00 yesterday and present 08:30.
I believe this should be simple solution but me being in a learning state I am challenged beyond the time I should be spending on it.
- I believe this to be the closest to what I need but everything becomes unclear when trying to apply the second filter to capture department:
Applying filter within a filter in JavaScript
some open tabs...
Find all matching elements with in an array of objects
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment