Lesson 2 of 11
Collect the day
Show on a big screenThe mela's check-in list has two mornings. A kite is written on it when it arrives, as one row. The sheet wants only today's.
Step 1 of 5
- Seven rows on the list: two from yesterday, five from today.
- Row Y1: day says yesterday. Skipped.
- Row Y2: day says yesterday. Skipped.
- Rows A1 to A5: day says today. Each one is kept, whole.
- Kept: 5. Yesterday's two rows stay on the list, untouched.
The rule
Collect walks the list and keeps today's rows. A row is kept whole or skipped whole. The day column says which one it is.
headers.indexOf("day")finds which position holds the day. Here,headersis the list of column names.row[dayColumn] === "today"is the test each row must pass. Here,dayColumnis the position found above.today.push(row)keeps the whole row — kite, span, tail and day, together. Here,todayis the new list. Thepushcall adds a row to its end.
A row that fails the test is not deleted. The list still holds it; only today's copy leaves it out. The loop reads every row once, in order. It does not skip any row.
Watch which rows are added to today and which are not.
Loading lab…
Predict which row the loop is reading. Predict how many kites it has kept. Then reveal it.
Try the lab to finish this lesson.