In this scenario, I have two arrays structured as follows:
arr1=[{room_no:1,bed_no:'1A'},
{room_no:1,bed_no:'1B'},
{room_no:2,bed_no:'2A'},
{room_no:3,bed_no:'3A'},
{room_no:3,bed_no:'3B'},
{room_no:4,bed_no:'4A'}]
arr2=[
{ patient_details:[{name:'patient1',age:22}],
patient_room_details:[{room_no:1,bed_no:'1A'}],
status:'occupied'
},
{ patient_room_details:[{room_no:1,bed_no:'1B'},
status:'available'
},
{ patient_details:[{name:'patient2',age:32}],
patient_room_details:[{room_no:2,bed_no:'2A'}],
status:'occupied'
}
{ patient_room_details:[{room_no:3,bed_no:'3A'},
status:'cleaning'
},
]
The goal is to compare the room_no and bed_no from the first array with the second array's patient_room_details. If a match is found, the object with patient_details, patient_room_details, and status is added to a result array. If no match is found, the status 'AVAILABLE' should be pushed.
Unfortunately, I'm facing issues pushing the status as AVAILABLE when there are no matches. Any assistance on this matter would be greatly appreciated.
The desired final outcome would look like this:
result=[
{ patient_details:[{name:'patient1',age:22}],
patient_room_details:[{room_no:1,bed_no:'1A'}],
status:'occupied'
},
{ patient_room_details:[{room_no:1,bed_no:'1B'},
status:'available'
},
{ patient_details:[{name:'patient2',age:32}],
patient_room_details:[{room_no:2,bed_no:'2A'}],
status:'occupied'
},
{ patient_room_details:[{room_no:3,bed_no:'3A'},
status:'cleaning'
},
{ patient_room_details:[{room_no:3,bed_no:'3B'},
status:'available'
},
{ patient_room_details:[{room_no:4,bed_no:'4A'},
status:'available'
},
]