Demo: Supply Bin Audit
The crew labels supply bins by code. An object associates each code with a count, so a requested code can be looked up without searching an array.
javascript
const bins = { cable: 2, adapter: 7, clip: 1 };
const requestedCode = "adapter";
const lowCodes = Object.entries(bins)
.filter(([code, count]) => count < 3)
.map(([code]) => code);
console.log(`${bins[requestedCode]} | ${lowCodes.join(", ")}`);
bins[requestedCode] uses the value of the variable as its property key; bins.requestedCode would look for a literal key with that spelling. Object.entries(bins) turns the record into [key, value] pairs so filter() and map() can find bins below three.
Checkpoint
Run this code, then change requestedCode to clip and run again. The count changes, while the low-bin list stays the same. In the exercise you will audit a separate volunteer schedule.