Two conditions, both true
Show on a big screenTwo conditions must both say yes. The steps below call each condition a door. A row must pass both doors.
- Five rows, the same five as before.
- First door: section is 9-A.
- Second door: due at least 1000.
- Only one of these five passes both.
The rule
Two conditions joined by and keep a row only when both hold. Two conditions keep fewer rows, or the same — never more.
Here sectionAt and dueAt hold the section and due positions. The sign >= means is at least. One if sits inside the other. So a row is added only after passing both.
const sectionAt = headers.indexOf('section');const dueAt = headers.indexOf('due');if (row[sectionAt] === '9-A') {if (row[dueAt] >= 1000) {answer.push(row);}}
Every kept row also passed the first condition. So the second one cannot add rows.
On the full register, this keeps 4 of the 12 records. They are A-101, A-106, A-108 and A-110.
Ask for due at least 0, and all 7 of 9-A pass. Every due is at least 0. That is the same count, not fewer.
Pick a section and slide the due below. Read who passes both.
Loading lab…
Fewer or the same — a second condition never adds a row.
Try the lab to finish this lesson.