Number = 10;
occupiedBeds = [2, 8];
I want to return numbers from 1 to number not equal to occupiedBeds, that is:
[1, 3, 4, 5, 6, 7, 9, 10]
My code so far:
const vacantBeds = (number) => {
const occupiedBeds = patientsData && patientsData.map((patient) => Number(patient.room.slice(-1)[0].bed))
let numArr = [...Array(number).keys()].map((x) => x + 1)
let filtered = numArr.filter((x) => x !== occupiedBeds)
return filtered.map((bed) => (
<option key={bed} value={bed}>
{bed}
</option>
))
}
number=10andbeds=[2,8], you want to return[1, 3,4,5,6,7, 9,10]- is that correct?numArr.filter((x) => !occupiedBeds.includes(x))