const censusMembers = Object.freeze([
{
id: 1,
name: 'Bob'
}, {
id: 2,
name: 'Sue'
}, {
id: 3,
name: 'Mary',
household_id: 2
}, {
id: 4,
name: 'Elizabeth',
household_id: 6
}, {
id: 5,
name: 'Tom'
}, {
id: 6,
name: 'Jill'
}, {
id: 7,
name: 'John',
household_id: 6
}
]);
In this array, A dependent can be determined by the presence of a household_id. The household_id is a reference to the ID of the employee that that member is a depended of (ex in the censusMembers list 'Mary' is a dependent of 'Sue')
How to build a function that takes in an id and the array of members(census members) and returns all dependents that belong to the user that has that id.
If the id is of a dependent, or isn't in the censusMember array then the function should return null.
If there are no dependents then the function should return an empty arrray.
for example:
if I give input as id 6 then output shoul be
[
{"id":4,"name":"Elizabeth","household_id":6},
{"id":7,"name":"John","household_id":6}
]
7or8would returnnulland5would return an empty array? Is that correct? If so, I personally find that a very uncomfortable API.