Looking for a solution with childcare schools - I have two sets of data that I need to match based on specific columns:
Attendance by Department: [date, department, 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...
Expenses by Department [date, department, 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"]
--
The goal is to link Expense.date && Expense.department to Attendance.date && Attendance.department ONLY if the .department appears in Attendance[] THEN, add Expense.expense to the corresponding record in Attendance
I've experimented with mapping, filtering, d3.js nest(), Object.assign(), ifs, $.each...
Here's the messy code snippet where I attempted different solutions even though they didn't really work as expected.
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 outcome: [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: pretty much everything but that.
My browser history shows 115 searches related to this issue from yesterday at 7 PM until today at 8:30 AM.
I feel like there should be a simple solution to this, but being in a learning phase, it's more challenging than I anticipated.
- I think I'm getting closer to what I need, although things get blurry when trying to apply the second filter to target departments:
Applying filter within a filter in JavaScript
some tabs stay open...
Find all matching elements within 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
Javascript multiple filters array
merge two arrays including some fields from each