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>
))
}
This should work for you
let filtered = numArr.filter( x => !occupiedBeds.includes(x))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With