When a learner can reproduce a familiar example but a small variation causes confusion, the problem is usually an incomplete model rather than a lack of effort. The fastest useful response is to expose the hidden state and test one boundary at a time.
JavaScript Iterator.prototype.reduce consumes a synchronous iterator and combines its values into one accumulator. Its central choices are whether an explicit initial value is present, which callback index is observed, what happens to an empty iterator, and how abrupt completion closes the underlying iterator. Mastery requires tracing consumption rather than borrowing an array mental model without checking the iterator contract. This guide begins with that mechanism, then develops it through worked traces, deliberate mistakes, explained practice and transfer decisions.
The aim is independent reasoning. A learner should be able to predict behaviour, locate the earliest wrong assumption, use a safe diagnostic procedure and defend a design choice in a new project.
Punggol families can use the guide in short sessions around homework, CCAs and rest. The activities are proposed learning exercises, not claims about a physical branch, timetable, class size, fee, school relationship or guaranteed result.
Use disposable data and repositories, preserve backups, and check version-sensitive details against the official source. Current documentation settles a technical contract; observation and explanation turn that contract into usable knowledge.
Find your next learning step
Choose the route that matches the present difficulty. Use the complete index for a systematic course.
Build the model
Chapters 1-4 . Begin here, then continue after the learner can predict, verify and explain.
Use the core tools
Chapters 5-8 . Begin here, then continue after the learner can predict, verify and explain.
Handle boundaries
Chapters 9-12 . Begin here, then continue after the learner can predict, verify and explain.
Debug and verify
Chapters 13-16 . Begin here, then continue after the learner can predict, verify and explain.
Transfer with judgment
Chapters 17-20 . Begin here, then continue after the learner can predict, verify and explain.
Open the full chapter index . Jump to capstone practice . Use the How Studying Works hub . Read the official documentation
Complete chapter index
Chapters 1-4 . Build the model
Chapters 5-8 . Use the core tools
Chapters 9-12 . Handle boundaries
Chapters 13-16 . Debug and verify
Calling reduce repeatedly requests values until the iterator is done and returns one accumulated result. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is calling reduce lazy because its input is an iterator. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Instrument next calls and observe that the method completes before returning.
For the reduce is a terminal iterator operation chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on calling reduce lazy because its input is an iterator. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const total=[1,2,3][Symbol.iterator]().reduce((a,v)=>a+v,0);
console.log(total);Explained result. The iterator is fully consumed and the returned total is 6. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: homework score stream. Predict the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Calling reduce repeatedly requests values until the iterator is done and returns one accumulated result.” Apply this procedure: Instrument next calls and observe that the method completes before returning. The expected mechanism is: The iterator is fully consumed and the returned total is 6. For the homework score stream, add one near-miss that exposes calling reduce lazy because its input is an iterator. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: library return queue. Contrast the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Calling reduce repeatedly requests values until the iterator is done and returns one accumulated result.” Apply this procedure: Instrument next calls and observe that the method completes before returning. The expected mechanism is: The iterator is fully consumed and the returned total is 6. For the library return queue, add one near-miss that exposes calling reduce lazy because its input is an iterator. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: CCA attendance iterator. Stress-test the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Calling reduce repeatedly requests values until the iterator is done and returns one accumulated result.” Apply this procedure: Instrument next calls and observe that the method completes before returning. The expected mechanism is: The iterator is fully consumed and the returned total is 6. For the CCA attendance iterator, add one near-miss that exposes calling reduce lazy because its input is an iterator. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: science reading generator. Explain the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Calling reduce repeatedly requests values until the iterator is done and returns one accumulated result.” Apply this procedure: Instrument next calls and observe that the method completes before returning. The expected mechanism is: The iterator is fully consumed and the returned total is 6. For the science reading generator, add one near-miss that exposes calling reduce lazy because its input is an iterator. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers calling reduce lazy because its input is an iterator.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Instrument next calls and observe that the method completes before returning.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from reduce is a terminal iterator operation?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing calling reduce lazy because its input is an iterator be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny photo metadata iterator with file sizes combined into a byte total. Include one ordinary case, one boundary and one deliberate failure caused by calling reduce lazy because its input is an iterator. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: Calling reduce repeatedly requests values until the iterator is done and returns one accumulated result. It shows a trace, not only a final value. The ordinary case should demonstrate “The iterator is fully consumed and the returned total is 6.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Instrument next calls and observe that the method completes before returning. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For reduce is a terminal iterator operation, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
CHAPTER 2 OF 20 . Build the model
2. The reducer receives accumulator, value and index
For each callback call, arguments are the current accumulator, current value and a numeric counter. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is copying an array callback signature and expecting the source object as a fourth argument. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Log arguments for a three-value iterator with an explicit seed.
For the The reducer receives accumulator, value and index chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on copying an array callback signature and expecting the source object as a fourth argument. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
[10,20][Symbol.iterator]().reduce((a,v,i)=>{console.log(i);return a+v;},0);Explained result. The reducer sees indices 0 and 1 because the explicit initial value makes the first element a callback value. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: CCA attendance iterator. Contrast the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “For each callback call, arguments are the current accumulator, current value and a numeric counter.” Apply this procedure: Log arguments for a three-value iterator with an explicit seed. The expected mechanism is: The reducer sees indices 0 and 1 because the explicit initial value makes the first element a callback value. For the CCA attendance iterator, add one near-miss that exposes copying an array callback signature and expecting the source object as a fourth argument. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: science reading generator. Stress-test the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “For each callback call, arguments are the current accumulator, current value and a numeric counter.” Apply this procedure: Log arguments for a three-value iterator with an explicit seed. The expected mechanism is: The reducer sees indices 0 and 1 because the explicit initial value makes the first element a callback value. For the science reading generator, add one near-miss that exposes copying an array callback signature and expecting the source object as a fourth argument. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: revision-card stream. Explain the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “For each callback call, arguments are the current accumulator, current value and a numeric counter.” Apply this procedure: Log arguments for a three-value iterator with an explicit seed. The expected mechanism is: The reducer sees indices 0 and 1 because the explicit initial value makes the first element a callback value. For the revision-card stream, add one near-miss that exposes copying an array callback signature and expecting the source object as a fourth argument. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: photo metadata iterator. Transfer the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “For each callback call, arguments are the current accumulator, current value and a numeric counter.” Apply this procedure: Log arguments for a three-value iterator with an explicit seed. The expected mechanism is: The reducer sees indices 0 and 1 because the explicit initial value makes the first element a callback value. For the photo metadata iterator, add one near-miss that exposes copying an array callback signature and expecting the source object as a fourth argument. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers copying an array callback signature and expecting the source object as a fourth argument.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Log arguments for a three-value iterator with an explicit seed.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from The reducer receives accumulator, value and index?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing copying an array callback signature and expecting the source object as a fourth argument be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny budget-entry generator with transactions folded into category balances. Include one ordinary case, one boundary and one deliberate failure caused by copying an array callback signature and expecting the source object as a fourth argument. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: For each callback call, arguments are the current accumulator, current value and a numeric counter. It shows a trace, not only a final value. The ordinary case should demonstrate “The reducer sees indices 0 and 1 because the explicit initial value makes the first element a callback value.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Log arguments for a three-value iterator with an explicit seed. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For The reducer receives accumulator, value and index, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
When initialValue is present, it becomes the first accumulator and every iterator value is passed to the reducer beginning at index 0. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is treating an explicit undefined seed as though the argument were absent. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Test omitted and explicitly supplied undefined as different calls.
For the An explicit initial value starts index zero chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on treating an explicit undefined seed as though the argument were absent. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const r=[2][Symbol.iterator]().reduce((a,v,i)=>[a,v,i],undefined);
console.log(r);Explained result. The callback runs once with accumulator undefined, value 2 and index 0. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: revision-card stream. Stress-test the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When initialValue is present, it becomes the first accumulator and every iterator value is passed to the reducer beginning at index 0.” Apply this procedure: Test omitted and explicitly supplied undefined as different calls. The expected mechanism is: The callback runs once with accumulator undefined, value 2 and index 0. For the revision-card stream, add one near-miss that exposes treating an explicit undefined seed as though the argument were absent. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: photo metadata iterator. Explain the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When initialValue is present, it becomes the first accumulator and every iterator value is passed to the reducer beginning at index 0.” Apply this procedure: Test omitted and explicitly supplied undefined as different calls. The expected mechanism is: The callback runs once with accumulator undefined, value 2 and index 0. For the photo metadata iterator, add one near-miss that exposes treating an explicit undefined seed as though the argument were absent. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: budget-entry generator. Transfer the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When initialValue is present, it becomes the first accumulator and every iterator value is passed to the reducer beginning at index 0.” Apply this procedure: Test omitted and explicitly supplied undefined as different calls. The expected mechanism is: The callback runs once with accumulator undefined, value 2 and index 0. For the budget-entry generator, add one near-miss that exposes treating an explicit undefined seed as though the argument were absent. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: project log iterator. Predict the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When initialValue is present, it becomes the first accumulator and every iterator value is passed to the reducer beginning at index 0.” Apply this procedure: Test omitted and explicitly supplied undefined as different calls. The expected mechanism is: The callback runs once with accumulator undefined, value 2 and index 0. For the project log iterator, add one near-miss that exposes treating an explicit undefined seed as though the argument were absent. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers treating an explicit undefined seed as though the argument were absent.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Test omitted and explicitly supplied undefined as different calls.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from An explicit initial value starts index zero?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing treating an explicit undefined seed as though the argument were absent be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny project log iterator with events reduced to the latest state. Include one ordinary case, one boundary and one deliberate failure caused by treating an explicit undefined seed as though the argument were absent. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: When initialValue is present, it becomes the first accumulator and every iterator value is passed to the reducer beginning at index 0. It shows a trace, not only a final value. The ordinary case should demonstrate “The callback runs once with accumulator undefined, value 2 and index 0.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Test omitted and explicitly supplied undefined as different calls. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For An explicit initial value starts index zero, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
CHAPTER 4 OF 20 . Build the model
4. Without a seed the first value becomes the accumulator
When initialValue is absent, reduce takes the first iterator value as accumulator and begins callbacks with the second value at index 1. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is expecting the reducer to see the first value with an implicit zero. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Use subtraction so the seed choice is visible.
For the Without a seed the first value becomes the accumulator chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on expecting the reducer to see the first value with an implicit zero. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const r=[10,3,2][Symbol.iterator]().reduce((a,v,i)=>a-v);
console.log(r);Explained result. The first accumulator is 10; callbacks subtract 3 at index 1 and 2 at index 2, producing 5. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: budget-entry generator. Explain the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When initialValue is absent, reduce takes the first iterator value as accumulator and begins callbacks with the second value at index 1.” Apply this procedure: Use subtraction so the seed choice is visible. The expected mechanism is: The first accumulator is 10; callbacks subtract 3 at index 1 and 2 at index 2, producing 5. For the budget-entry generator, add one near-miss that exposes expecting the reducer to see the first value with an implicit zero. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: project log iterator. Transfer the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When initialValue is absent, reduce takes the first iterator value as accumulator and begins callbacks with the second value at index 1.” Apply this procedure: Use subtraction so the seed choice is visible. The expected mechanism is: The first accumulator is 10; callbacks subtract 3 at index 1 and 2 at index 2, producing 5. For the project log iterator, add one near-miss that exposes expecting the reducer to see the first value with an implicit zero. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: homework score stream. Predict the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When initialValue is absent, reduce takes the first iterator value as accumulator and begins callbacks with the second value at index 1.” Apply this procedure: Use subtraction so the seed choice is visible. The expected mechanism is: The first accumulator is 10; callbacks subtract 3 at index 1 and 2 at index 2, producing 5. For the homework score stream, add one near-miss that exposes expecting the reducer to see the first value with an implicit zero. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: library return queue. Contrast the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When initialValue is absent, reduce takes the first iterator value as accumulator and begins callbacks with the second value at index 1.” Apply this procedure: Use subtraction so the seed choice is visible. The expected mechanism is: The first accumulator is 10; callbacks subtract 3 at index 1 and 2 at index 2, producing 5. For the library return queue, add one near-miss that exposes expecting the reducer to see the first value with an implicit zero. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers expecting the reducer to see the first value with an implicit zero.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Use subtraction so the seed choice is visible.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Without a seed the first value becomes the accumulator?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing expecting the reducer to see the first value with an implicit zero be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny homework score stream with scores produced one at a time from a generator. Include one ordinary case, one boundary and one deliberate failure caused by expecting the reducer to see the first value with an implicit zero. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: When initialValue is absent, reduce takes the first iterator value as accumulator and begins callbacks with the second value at index 1. It shows a trace, not only a final value. The ordinary case should demonstrate “The first accumulator is 10; callbacks subtract 3 at index 1 and 2 at index 2, producing 5.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Use subtraction so the seed choice is visible. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Without a seed the first value becomes the accumulator, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
If no seed is supplied and the iterator is already done, reduce throws TypeError. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is expecting undefined or zero for every empty reduction. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Decide the mathematical identity and provide it explicitly when empty input is valid.
For the Empty without an initial value throws chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on expecting undefined or zero for every empty reduction. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
try{[][Symbol.iterator]().reduce((a,v)=>a+v);}catch(e){console.log(e.name);}Explained result. The observation is TypeError because there is neither a seed nor a first value. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: homework score stream. Transfer the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If no seed is supplied and the iterator is already done, reduce throws TypeError.” Apply this procedure: Decide the mathematical identity and provide it explicitly when empty input is valid. The expected mechanism is: The observation is TypeError because there is neither a seed nor a first value. For the homework score stream, add one near-miss that exposes expecting undefined or zero for every empty reduction. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: library return queue. Predict the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If no seed is supplied and the iterator is already done, reduce throws TypeError.” Apply this procedure: Decide the mathematical identity and provide it explicitly when empty input is valid. The expected mechanism is: The observation is TypeError because there is neither a seed nor a first value. For the library return queue, add one near-miss that exposes expecting undefined or zero for every empty reduction. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: CCA attendance iterator. Contrast the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If no seed is supplied and the iterator is already done, reduce throws TypeError.” Apply this procedure: Decide the mathematical identity and provide it explicitly when empty input is valid. The expected mechanism is: The observation is TypeError because there is neither a seed nor a first value. For the CCA attendance iterator, add one near-miss that exposes expecting undefined or zero for every empty reduction. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: science reading generator. Stress-test the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If no seed is supplied and the iterator is already done, reduce throws TypeError.” Apply this procedure: Decide the mathematical identity and provide it explicitly when empty input is valid. The expected mechanism is: The observation is TypeError because there is neither a seed nor a first value. For the science reading generator, add one near-miss that exposes expecting undefined or zero for every empty reduction. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers expecting undefined or zero for every empty reduction.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Decide the mathematical identity and provide it explicitly when empty input is valid.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Empty without an initial value throws?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing expecting undefined or zero for every empty reduction be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny library return queue with book records folded into category counts. Include one ordinary case, one boundary and one deliberate failure caused by expecting undefined or zero for every empty reduction. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: If no seed is supplied and the iterator is already done, reduce throws TypeError. It shows a trace, not only a final value. The ordinary case should demonstrate “The observation is TypeError because there is neither a seed nor a first value.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Decide the mathematical identity and provide it explicitly when empty input is valid. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Empty without an initial value throws, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
If the iterator is empty and a seed is present, the seed is returned without calling the reducer. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is adding a reducer side effect that must run even when there are no values. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Keep required finalisation outside the reducer and count callback calls in a test.
For the Empty with an initial value returns the seed chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on adding a reducer side effect that must run even when there are no values. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
let calls=0; const seed={n:0};
const r=[][Symbol.iterator]().reduce(a=>{calls++;return a;},seed);
console.log(r===seed,calls);Explained result. The result is the same seed object and calls is zero. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: CCA attendance iterator. Predict the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If the iterator is empty and a seed is present, the seed is returned without calling the reducer.” Apply this procedure: Keep required finalisation outside the reducer and count callback calls in a test. The expected mechanism is: The result is the same seed object and calls is zero. For the CCA attendance iterator, add one near-miss that exposes adding a reducer side effect that must run even when there are no values. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: science reading generator. Contrast the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If the iterator is empty and a seed is present, the seed is returned without calling the reducer.” Apply this procedure: Keep required finalisation outside the reducer and count callback calls in a test. The expected mechanism is: The result is the same seed object and calls is zero. For the science reading generator, add one near-miss that exposes adding a reducer side effect that must run even when there are no values. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: revision-card stream. Stress-test the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If the iterator is empty and a seed is present, the seed is returned without calling the reducer.” Apply this procedure: Keep required finalisation outside the reducer and count callback calls in a test. The expected mechanism is: The result is the same seed object and calls is zero. For the revision-card stream, add one near-miss that exposes adding a reducer side effect that must run even when there are no values. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: photo metadata iterator. Explain the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If the iterator is empty and a seed is present, the seed is returned without calling the reducer.” Apply this procedure: Keep required finalisation outside the reducer and count callback calls in a test. The expected mechanism is: The result is the same seed object and calls is zero. For the photo metadata iterator, add one near-miss that exposes adding a reducer side effect that must run even when there are no values. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers adding a reducer side effect that must run even when there are no values.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Keep required finalisation outside the reducer and count callback calls in a test.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Empty with an initial value returns the seed?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing adding a reducer side effect that must run even when there are no values be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny CCA attendance iterator with sign-ins combined into a summary object. Include one ordinary case, one boundary and one deliberate failure caused by adding a reducer side effect that must run even when there are no values. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: If the iterator is empty and a seed is present, the seed is returned without calling the reducer. It shows a trace, not only a final value. The ordinary case should demonstrate “The result is the same seed object and calls is zero.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Keep required finalisation outside the reducer and count callback calls in a test. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Empty with an initial value returns the seed, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
A one-value iterator supplies its only value as accumulator and finishes before the reducer is needed. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is putting validation only inside the reducer and missing single-item input. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Validate values upstream or provide a seed when every value must pass through callback logic.
For the One value without a seed skips the callback chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on putting validation only inside the reducer and missing single-item input. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
let calls=0; const r=[7][Symbol.iterator]().reduce((a,v)=>{calls++;return a+v;});
console.log(r,calls);Explained result. The result is 7 and the reducer call count is zero. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: revision-card stream. Contrast the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A one-value iterator supplies its only value as accumulator and finishes before the reducer is needed.” Apply this procedure: Validate values upstream or provide a seed when every value must pass through callback logic. The expected mechanism is: The result is 7 and the reducer call count is zero. For the revision-card stream, add one near-miss that exposes putting validation only inside the reducer and missing single-item input. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: photo metadata iterator. Stress-test the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A one-value iterator supplies its only value as accumulator and finishes before the reducer is needed.” Apply this procedure: Validate values upstream or provide a seed when every value must pass through callback logic. The expected mechanism is: The result is 7 and the reducer call count is zero. For the photo metadata iterator, add one near-miss that exposes putting validation only inside the reducer and missing single-item input. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: budget-entry generator. Explain the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A one-value iterator supplies its only value as accumulator and finishes before the reducer is needed.” Apply this procedure: Validate values upstream or provide a seed when every value must pass through callback logic. The expected mechanism is: The result is 7 and the reducer call count is zero. For the budget-entry generator, add one near-miss that exposes putting validation only inside the reducer and missing single-item input. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: project log iterator. Transfer the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A one-value iterator supplies its only value as accumulator and finishes before the reducer is needed.” Apply this procedure: Validate values upstream or provide a seed when every value must pass through callback logic. The expected mechanism is: The result is 7 and the reducer call count is zero. For the project log iterator, add one near-miss that exposes putting validation only inside the reducer and missing single-item input. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers putting validation only inside the reducer and missing single-item input.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Validate values upstream or provide a seed when every value must pass through callback logic.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from One value without a seed skips the callback?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing putting validation only inside the reducer and missing single-item input be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny science reading generator with measurements accumulated into total and count. Include one ordinary case, one boundary and one deliberate failure caused by putting validation only inside the reducer and missing single-item input. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: A one-value iterator supplies its only value as accumulator and finishes before the reducer is needed. It shows a trace, not only a final value. The ordinary case should demonstrate “The result is 7 and the reducer call count is zero.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Validate values upstream or provide a seed when every value must pass through callback logic. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For One value without a seed skips the callback, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
reduce advances the iterator object itself; after successful completion, later next calls report done. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is expecting to reduce and then iterate the same source again. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Create a fresh iterator for each independent pass or materialise deliberately.
For the The original iterator is single-pass chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on expecting to reduce and then iterate the same source again. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const it=[1,2][Symbol.iterator]();
console.log(it.reduce((a,v)=>a+v,0));
console.log(it.next());Explained result. The total is 3 and the next result is done because reduction consumed the iterator. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: budget-entry generator. Stress-test the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “reduce advances the iterator object itself; after successful completion, later next calls report done.” Apply this procedure: Create a fresh iterator for each independent pass or materialise deliberately. The expected mechanism is: The total is 3 and the next result is done because reduction consumed the iterator. For the budget-entry generator, add one near-miss that exposes expecting to reduce and then iterate the same source again. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: project log iterator. Explain the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “reduce advances the iterator object itself; after successful completion, later next calls report done.” Apply this procedure: Create a fresh iterator for each independent pass or materialise deliberately. The expected mechanism is: The total is 3 and the next result is done because reduction consumed the iterator. For the project log iterator, add one near-miss that exposes expecting to reduce and then iterate the same source again. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: homework score stream. Transfer the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “reduce advances the iterator object itself; after successful completion, later next calls report done.” Apply this procedure: Create a fresh iterator for each independent pass or materialise deliberately. The expected mechanism is: The total is 3 and the next result is done because reduction consumed the iterator. For the homework score stream, add one near-miss that exposes expecting to reduce and then iterate the same source again. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: library return queue. Predict the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “reduce advances the iterator object itself; after successful completion, later next calls report done.” Apply this procedure: Create a fresh iterator for each independent pass or materialise deliberately. The expected mechanism is: The total is 3 and the next result is done because reduction consumed the iterator. For the library return queue, add one near-miss that exposes expecting to reduce and then iterate the same source again. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers expecting to reduce and then iterate the same source again.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Create a fresh iterator for each independent pass or materialise deliberately.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from The original iterator is single-pass?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing expecting to reduce and then iterate the same source again be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny revision-card stream with confidence values reduced to a minimum. Include one ordinary case, one boundary and one deliberate failure caused by expecting to reduce and then iterate the same source again. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: reduce advances the iterator object itself; after successful completion, later next calls report done. It shows a trace, not only a final value. The ordinary case should demonstrate “The total is 3 and the next result is done because reduction consumed the iterator.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Create a fresh iterator for each independent pass or materialise deliberately. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For The original iterator is single-pass, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
An iterator has next-based consumption and no array length, holes or stable random access contract. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is transferring claims about sparse array holes to iterator values. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the protocol that produces values before comparing APIs.
For the Iterator.reduce is not Array.reduce chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on transferring claims about sparse array holes to iterator values. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const it=Iterator.from([,2]);
console.log(it.reduce((a,v)=>a+[String(v)],''));Explained result. Iterator.from observes values yielded by the array iterator, including undefined for the hole, rather than Array.reduce skipping an unassigned index. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: homework score stream. Explain the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “An iterator has next-based consumption and no array length, holes or stable random access contract.” Apply this procedure: State the protocol that produces values before comparing APIs. The expected mechanism is: Iterator.from observes values yielded by the array iterator, including undefined for the hole, rather than Array.reduce skipping an unassigned index. For the homework score stream, add one near-miss that exposes transferring claims about sparse array holes to iterator values. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: library return queue. Transfer the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “An iterator has next-based consumption and no array length, holes or stable random access contract.” Apply this procedure: State the protocol that produces values before comparing APIs. The expected mechanism is: Iterator.from observes values yielded by the array iterator, including undefined for the hole, rather than Array.reduce skipping an unassigned index. For the library return queue, add one near-miss that exposes transferring claims about sparse array holes to iterator values. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: CCA attendance iterator. Predict the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “An iterator has next-based consumption and no array length, holes or stable random access contract.” Apply this procedure: State the protocol that produces values before comparing APIs. The expected mechanism is: Iterator.from observes values yielded by the array iterator, including undefined for the hole, rather than Array.reduce skipping an unassigned index. For the CCA attendance iterator, add one near-miss that exposes transferring claims about sparse array holes to iterator values. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: science reading generator. Contrast the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “An iterator has next-based consumption and no array length, holes or stable random access contract.” Apply this procedure: State the protocol that produces values before comparing APIs. The expected mechanism is: Iterator.from observes values yielded by the array iterator, including undefined for the hole, rather than Array.reduce skipping an unassigned index. For the science reading generator, add one near-miss that exposes transferring claims about sparse array holes to iterator values. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers transferring claims about sparse array holes to iterator values.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “State the protocol that produces values before comparing APIs.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Iterator.reduce is not Array.reduce?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing transferring claims about sparse array holes to iterator values be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny photo metadata iterator with file sizes combined into a byte total. Include one ordinary case, one boundary and one deliberate failure caused by transferring claims about sparse array holes to iterator values. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: An iterator has next-based consumption and no array length, holes or stable random access contract. It shows a trace, not only a final value. The ordinary case should demonstrate “Iterator.from observes values yielded by the array iterator, including undefined for the hole, rather than Array.reduce skipping an unassigned index.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the protocol that produces values before comparing APIs. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Iterator.reduce is not Array.reduce, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
A non-callable reducer causes TypeError rather than being coerced into a function. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is passing a configuration value and diagnosing the failure as an iterator problem. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Validate the reducer boundary before consuming a stateful source.
For the The callback must be callable chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on passing a configuration value and diagnosing the failure as an iterator problem. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
try{[1][Symbol.iterator]().reduce(null,0);}catch(e){console.log(e.name);}Explained result. The call throws TypeError because null is not callable. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: CCA attendance iterator. Transfer the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A non-callable reducer causes TypeError rather than being coerced into a function.” Apply this procedure: Validate the reducer boundary before consuming a stateful source. The expected mechanism is: The call throws TypeError because null is not callable. For the CCA attendance iterator, add one near-miss that exposes passing a configuration value and diagnosing the failure as an iterator problem. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: science reading generator. Predict the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A non-callable reducer causes TypeError rather than being coerced into a function.” Apply this procedure: Validate the reducer boundary before consuming a stateful source. The expected mechanism is: The call throws TypeError because null is not callable. For the science reading generator, add one near-miss that exposes passing a configuration value and diagnosing the failure as an iterator problem. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: revision-card stream. Contrast the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A non-callable reducer causes TypeError rather than being coerced into a function.” Apply this procedure: Validate the reducer boundary before consuming a stateful source. The expected mechanism is: The call throws TypeError because null is not callable. For the revision-card stream, add one near-miss that exposes passing a configuration value and diagnosing the failure as an iterator problem. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: photo metadata iterator. Stress-test the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A non-callable reducer causes TypeError rather than being coerced into a function.” Apply this procedure: Validate the reducer boundary before consuming a stateful source. The expected mechanism is: The call throws TypeError because null is not callable. For the photo metadata iterator, add one near-miss that exposes passing a configuration value and diagnosing the failure as an iterator problem. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers passing a configuration value and diagnosing the failure as an iterator problem.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Validate the reducer boundary before consuming a stateful source.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from The callback must be callable?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing passing a configuration value and diagnosing the failure as an iterator problem be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny budget-entry generator with transactions folded into category balances. Include one ordinary case, one boundary and one deliberate failure caused by passing a configuration value and diagnosing the failure as an iterator problem. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: A non-callable reducer causes TypeError rather than being coerced into a function. It shows a trace, not only a final value. The ordinary case should demonstrate “The call throws TypeError because null is not callable.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Validate the reducer boundary before consuming a stateful source. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For The callback must be callable, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
The reducer is called without a receiver; in strict code its this value is undefined. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is depending on a method receiver that reduce never supplies. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Close over explicit state or bind the function deliberately before passing it.
For the Reducer this is undefined chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on depending on a method receiver that reduce never supplies. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
function f(a,v){'use strict'; console.log(this); return a+v;}
[1][Symbol.iterator]().reduce(f,0);Explained result. The logged this value is undefined. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: revision-card stream. Predict the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “The reducer is called without a receiver; in strict code its this value is undefined.” Apply this procedure: Close over explicit state or bind the function deliberately before passing it. The expected mechanism is: The logged this value is undefined. For the revision-card stream, add one near-miss that exposes depending on a method receiver that reduce never supplies. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: photo metadata iterator. Contrast the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “The reducer is called without a receiver; in strict code its this value is undefined.” Apply this procedure: Close over explicit state or bind the function deliberately before passing it. The expected mechanism is: The logged this value is undefined. For the photo metadata iterator, add one near-miss that exposes depending on a method receiver that reduce never supplies. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: budget-entry generator. Stress-test the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “The reducer is called without a receiver; in strict code its this value is undefined.” Apply this procedure: Close over explicit state or bind the function deliberately before passing it. The expected mechanism is: The logged this value is undefined. For the budget-entry generator, add one near-miss that exposes depending on a method receiver that reduce never supplies. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: project log iterator. Explain the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “The reducer is called without a receiver; in strict code its this value is undefined.” Apply this procedure: Close over explicit state or bind the function deliberately before passing it. The expected mechanism is: The logged this value is undefined. For the project log iterator, add one near-miss that exposes depending on a method receiver that reduce never supplies. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers depending on a method receiver that reduce never supplies.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Close over explicit state or bind the function deliberately before passing it.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Reducer this is undefined?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing depending on a method receiver that reduce never supplies be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny project log iterator with events reduced to the latest state. Include one ordinary case, one boundary and one deliberate failure caused by depending on a method receiver that reduce never supplies. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: The reducer is called without a receiver; in strict code its this value is undefined. It shows a trace, not only a final value. The ordinary case should demonstrate “The logged this value is undefined.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Close over explicit state or bind the function deliberately before passing it. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Reducer this is undefined, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
If the reducer throws, reduction does not produce a partial final result and the abrupt completion is propagated. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is catching outside and assuming remaining values were still visited. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Log yielded values and reducer calls around one deliberate throw.
For the A thrown reducer error stops reduction chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on catching outside and assuming remaining values were still visited. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
function* g(){yield 1;yield 2;yield 3;}
try{g().reduce((a,v)=>{if(v===2)throw Error('stop');return a+v;},0);}catch(e){console.log(e.message);}Explained result. The error stop is rethrown and the value 3 is not reduced. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: budget-entry generator. Contrast the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If the reducer throws, reduction does not produce a partial final result and the abrupt completion is propagated.” Apply this procedure: Log yielded values and reducer calls around one deliberate throw. The expected mechanism is: The error stop is rethrown and the value 3 is not reduced. For the budget-entry generator, add one near-miss that exposes catching outside and assuming remaining values were still visited. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: project log iterator. Stress-test the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If the reducer throws, reduction does not produce a partial final result and the abrupt completion is propagated.” Apply this procedure: Log yielded values and reducer calls around one deliberate throw. The expected mechanism is: The error stop is rethrown and the value 3 is not reduced. For the project log iterator, add one near-miss that exposes catching outside and assuming remaining values were still visited. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: homework score stream. Explain the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If the reducer throws, reduction does not produce a partial final result and the abrupt completion is propagated.” Apply this procedure: Log yielded values and reducer calls around one deliberate throw. The expected mechanism is: The error stop is rethrown and the value 3 is not reduced. For the homework score stream, add one near-miss that exposes catching outside and assuming remaining values were still visited. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: library return queue. Transfer the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “If the reducer throws, reduction does not produce a partial final result and the abrupt completion is propagated.” Apply this procedure: Log yielded values and reducer calls around one deliberate throw. The expected mechanism is: The error stop is rethrown and the value 3 is not reduced. For the library return queue, add one near-miss that exposes catching outside and assuming remaining values were still visited. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers catching outside and assuming remaining values were still visited.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Log yielded values and reducer calls around one deliberate throw.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from A thrown reducer error stops reduction?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing catching outside and assuming remaining values were still visited be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny homework score stream with scores produced one at a time from a generator. Include one ordinary case, one boundary and one deliberate failure caused by catching outside and assuming remaining values were still visited. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: If the reducer throws, reduction does not produce a partial final result and the abrupt completion is propagated. It shows a trace, not only a final value. The ordinary case should demonstrate “The error stop is rethrown and the value 3 is not reduced.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Log yielded values and reducer calls around one deliberate throw. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For A thrown reducer error stops reduction, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
When callback evaluation fails, the iterator-close protocol invokes a return method when present before propagating the error. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is assuming a generator finally block runs only after natural exhaustion. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Put cleanup in a generator finally block and force a reducer error.
For the Abrupt completion closes the iterator chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on assuming a generator finally block runs only after natural exhaustion. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
function* g(){try{yield 1;yield 2;}finally{console.log('closed');}}
try{g().reduce(()=>{throw Error('x');},0);}catch{}Explained result. The generator prints closed because abrupt completion closes the underlying iterator. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: homework score stream. Stress-test the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When callback evaluation fails, the iterator-close protocol invokes a return method when present before propagating the error.” Apply this procedure: Put cleanup in a generator finally block and force a reducer error. The expected mechanism is: The generator prints closed because abrupt completion closes the underlying iterator. For the homework score stream, add one near-miss that exposes assuming a generator finally block runs only after natural exhaustion. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: library return queue. Explain the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When callback evaluation fails, the iterator-close protocol invokes a return method when present before propagating the error.” Apply this procedure: Put cleanup in a generator finally block and force a reducer error. The expected mechanism is: The generator prints closed because abrupt completion closes the underlying iterator. For the library return queue, add one near-miss that exposes assuming a generator finally block runs only after natural exhaustion. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: CCA attendance iterator. Transfer the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When callback evaluation fails, the iterator-close protocol invokes a return method when present before propagating the error.” Apply this procedure: Put cleanup in a generator finally block and force a reducer error. The expected mechanism is: The generator prints closed because abrupt completion closes the underlying iterator. For the CCA attendance iterator, add one near-miss that exposes assuming a generator finally block runs only after natural exhaustion. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: science reading generator. Predict the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “When callback evaluation fails, the iterator-close protocol invokes a return method when present before propagating the error.” Apply this procedure: Put cleanup in a generator finally block and force a reducer error. The expected mechanism is: The generator prints closed because abrupt completion closes the underlying iterator. For the science reading generator, add one near-miss that exposes assuming a generator finally block runs only after natural exhaustion. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers assuming a generator finally block runs only after natural exhaustion.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Put cleanup in a generator finally block and force a reducer error.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Abrupt completion closes the iterator?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing assuming a generator finally block runs only after natural exhaustion be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny library return queue with book records folded into category counts. Include one ordinary case, one boundary and one deliberate failure caused by assuming a generator finally block runs only after natural exhaustion. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: When callback evaluation fails, the iterator-close protocol invokes a return method when present before propagating the error. It shows a trace, not only a final value. The ordinary case should demonstrate “The generator prints closed because abrupt completion closes the underlying iterator.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Put cleanup in a generator finally block and force a reducer error. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Abrupt completion closes the iterator, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
JavaScript does not require the accumulator to keep one type, although changing it casually makes reasoning difficult. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is starting with a number and returning an object without documenting the transition. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Choose one stable accumulator shape and assert it after each step in development.
For the Accumulator type can change chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on starting with a number and returning an object without documenting the transition. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const r=[1,2][Symbol.iterator]().reduce((a,v)=>({sum:a.sum+v}),{sum:0});Explained result. The accumulator stays an object with a numeric sum and ends as {sum:3}. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: CCA attendance iterator. Explain the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “JavaScript does not require the accumulator to keep one type, although changing it casually makes reasoning difficult.” Apply this procedure: Choose one stable accumulator shape and assert it after each step in development. The expected mechanism is: The accumulator stays an object with a numeric sum and ends as {sum:3}. For the CCA attendance iterator, add one near-miss that exposes starting with a number and returning an object without documenting the transition. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: science reading generator. Transfer the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “JavaScript does not require the accumulator to keep one type, although changing it casually makes reasoning difficult.” Apply this procedure: Choose one stable accumulator shape and assert it after each step in development. The expected mechanism is: The accumulator stays an object with a numeric sum and ends as {sum:3}. For the science reading generator, add one near-miss that exposes starting with a number and returning an object without documenting the transition. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: revision-card stream. Predict the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “JavaScript does not require the accumulator to keep one type, although changing it casually makes reasoning difficult.” Apply this procedure: Choose one stable accumulator shape and assert it after each step in development. The expected mechanism is: The accumulator stays an object with a numeric sum and ends as {sum:3}. For the revision-card stream, add one near-miss that exposes starting with a number and returning an object without documenting the transition. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: photo metadata iterator. Contrast the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “JavaScript does not require the accumulator to keep one type, although changing it casually makes reasoning difficult.” Apply this procedure: Choose one stable accumulator shape and assert it after each step in development. The expected mechanism is: The accumulator stays an object with a numeric sum and ends as {sum:3}. For the photo metadata iterator, add one near-miss that exposes starting with a number and returning an object without documenting the transition. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers starting with a number and returning an object without documenting the transition.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Choose one stable accumulator shape and assert it after each step in development.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Accumulator type can change?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing starting with a number and returning an object without documenting the transition be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny CCA attendance iterator with sign-ins combined into a summary object. Include one ordinary case, one boundary and one deliberate failure caused by starting with a number and returning an object without documenting the transition. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: JavaScript does not require the accumulator to keep one type, although changing it casually makes reasoning difficult. It shows a trace, not only a final value. The ordinary case should demonstrate “The accumulator stays an object with a numeric sum and ends as {sum:3}.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Choose one stable accumulator shape and assert it after each step in development. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Accumulator type can change, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
CHAPTER 15 OF 20 . Debug and verify
15. Mutable accumulators are returned by identity
A reducer may mutate and return the same array, Map or object seed on each call. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is calling the result immutable merely because reduce returns one value. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Compare identity and decide whether callers may retain the seed.
For the Mutable accumulators are returned by identity chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on calling the result immutable merely because reduce returns one value. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const seed=[]; const r=[1,2][Symbol.iterator]().reduce((a,v)=>(a.push(v),a),seed);
console.log(r===seed,seed);Explained result. The identity check is true and seed now contains 1 and 2. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: revision-card stream. Transfer the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A reducer may mutate and return the same array, Map or object seed on each call.” Apply this procedure: Compare identity and decide whether callers may retain the seed. The expected mechanism is: The identity check is true and seed now contains 1 and 2. For the revision-card stream, add one near-miss that exposes calling the result immutable merely because reduce returns one value. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: photo metadata iterator. Predict the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A reducer may mutate and return the same array, Map or object seed on each call.” Apply this procedure: Compare identity and decide whether callers may retain the seed. The expected mechanism is: The identity check is true and seed now contains 1 and 2. For the photo metadata iterator, add one near-miss that exposes calling the result immutable merely because reduce returns one value. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: budget-entry generator. Contrast the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A reducer may mutate and return the same array, Map or object seed on each call.” Apply this procedure: Compare identity and decide whether callers may retain the seed. The expected mechanism is: The identity check is true and seed now contains 1 and 2. For the budget-entry generator, add one near-miss that exposes calling the result immutable merely because reduce returns one value. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: project log iterator. Stress-test the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A reducer may mutate and return the same array, Map or object seed on each call.” Apply this procedure: Compare identity and decide whether callers may retain the seed. The expected mechanism is: The identity check is true and seed now contains 1 and 2. For the project log iterator, add one near-miss that exposes calling the result immutable merely because reduce returns one value. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers calling the result immutable merely because reduce returns one value.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Compare identity and decide whether callers may retain the seed.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Mutable accumulators are returned by identity?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing calling the result immutable merely because reduce returns one value be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny science reading generator with measurements accumulated into total and count. Include one ordinary case, one boundary and one deliberate failure caused by calling the result immutable merely because reduce returns one value. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: A reducer may mutate and return the same array, Map or object seed on each call. It shows a trace, not only a final value. The ordinary case should demonstrate “The identity check is true and seed now contains 1 and 2.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Compare identity and decide whether callers may retain the seed. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Mutable accumulators are returned by identity, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
CHAPTER 16 OF 20 . Debug and verify
16. Immutable accumulation trades allocation for clearer snapshots
Returning a new accumulator each step can simplify reasoning but may allocate substantially for large streams. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is spreading a growing array on every step without measuring cost. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Benchmark realistic data and choose a structure whose update cost fits the job.
For the Immutable accumulation trades allocation for clearer snapshots chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on spreading a growing array on every step without measuring cost. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const r=['a','b'][Symbol.iterator]().reduce((a,v)=>({...a,[v]:true}),{});Explained result. The final object has keys a and b, while each step created a new object. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: budget-entry generator. Predict the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Returning a new accumulator each step can simplify reasoning but may allocate substantially for large streams.” Apply this procedure: Benchmark realistic data and choose a structure whose update cost fits the job. The expected mechanism is: The final object has keys a and b, while each step created a new object. For the budget-entry generator, add one near-miss that exposes spreading a growing array on every step without measuring cost. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: project log iterator. Contrast the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Returning a new accumulator each step can simplify reasoning but may allocate substantially for large streams.” Apply this procedure: Benchmark realistic data and choose a structure whose update cost fits the job. The expected mechanism is: The final object has keys a and b, while each step created a new object. For the project log iterator, add one near-miss that exposes spreading a growing array on every step without measuring cost. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: homework score stream. Stress-test the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Returning a new accumulator each step can simplify reasoning but may allocate substantially for large streams.” Apply this procedure: Benchmark realistic data and choose a structure whose update cost fits the job. The expected mechanism is: The final object has keys a and b, while each step created a new object. For the homework score stream, add one near-miss that exposes spreading a growing array on every step without measuring cost. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: library return queue. Explain the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Returning a new accumulator each step can simplify reasoning but may allocate substantially for large streams.” Apply this procedure: Benchmark realistic data and choose a structure whose update cost fits the job. The expected mechanism is: The final object has keys a and b, while each step created a new object. For the library return queue, add one near-miss that exposes spreading a growing array on every step without measuring cost. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers spreading a growing array on every step without measuring cost.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Benchmark realistic data and choose a structure whose update cost fits the job.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Immutable accumulation trades allocation for clearer snapshots?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing spreading a growing array on every step without measuring cost be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny revision-card stream with confidence values reduced to a minimum. Include one ordinary case, one boundary and one deliberate failure caused by spreading a growing array on every step without measuring cost. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: Returning a new accumulator each step can simplify reasoning but may allocate substantially for large streams. It shows a trace, not only a final value. The ordinary case should demonstrate “The final object has keys a and b, while each step created a new object.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Benchmark realistic data and choose a structure whose update cost fits the job. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Immutable accumulation trades allocation for clearer snapshots, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
CHAPTER 17 OF 20 . Transfer with judgment
17. Infinite iterators never finish on their own
Because reduce is terminal and seeks done, an infinite source prevents a result unless an upstream helper bounds it. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is calling reduce directly on an unbounded generator and waiting for a total. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Use take, a finite producer or a domain stopping condition before reduction.
For the Infinite iterators never finish on their own chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on calling reduce directly on an unbounded generator and waiting for a total. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const firstFive=Iterator.from((function*(){let n=1;while(true)yield n++;})()).take(5);
console.log(firstFive.reduce((a,v)=>a+v,0));Explained result. take(5) bounds consumption and the total is 15. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: homework score stream. Contrast the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Because reduce is terminal and seeks done, an infinite source prevents a result unless an upstream helper bounds it.” Apply this procedure: Use take, a finite producer or a domain stopping condition before reduction. The expected mechanism is: take(5) bounds consumption and the total is 15. For the homework score stream, add one near-miss that exposes calling reduce directly on an unbounded generator and waiting for a total. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: library return queue. Stress-test the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Because reduce is terminal and seeks done, an infinite source prevents a result unless an upstream helper bounds it.” Apply this procedure: Use take, a finite producer or a domain stopping condition before reduction. The expected mechanism is: take(5) bounds consumption and the total is 15. For the library return queue, add one near-miss that exposes calling reduce directly on an unbounded generator and waiting for a total. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: CCA attendance iterator. Explain the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Because reduce is terminal and seeks done, an infinite source prevents a result unless an upstream helper bounds it.” Apply this procedure: Use take, a finite producer or a domain stopping condition before reduction. The expected mechanism is: take(5) bounds consumption and the total is 15. For the CCA attendance iterator, add one near-miss that exposes calling reduce directly on an unbounded generator and waiting for a total. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: science reading generator. Transfer the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Because reduce is terminal and seeks done, an infinite source prevents a result unless an upstream helper bounds it.” Apply this procedure: Use take, a finite producer or a domain stopping condition before reduction. The expected mechanism is: take(5) bounds consumption and the total is 15. For the science reading generator, add one near-miss that exposes calling reduce directly on an unbounded generator and waiting for a total. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers calling reduce directly on an unbounded generator and waiting for a total.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Use take, a finite producer or a domain stopping condition before reduction.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Infinite iterators never finish on their own?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing calling reduce directly on an unbounded generator and waiting for a total be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny photo metadata iterator with file sizes combined into a byte total. Include one ordinary case, one boundary and one deliberate failure caused by calling reduce directly on an unbounded generator and waiting for a total. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: Because reduce is terminal and seeks done, an infinite source prevents a result unless an upstream helper bounds it. It shows a trace, not only a final value. The ordinary case should demonstrate “take(5) bounds consumption and the total is 15.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Use take, a finite producer or a domain stopping condition before reduction. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Infinite iterators never finish on their own, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
CHAPTER 18 OF 20 . Transfer with judgment
18. Pipeline order changes work and meaning
map, filter, drop and take transform consumption before reduce, so moving them changes which values and side effects participate. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is reordering helpers as a cosmetic refactor. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Write the yielded sequence after each stage before calculating the reduction.
For the Pipeline order changes work and meaning chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on reordering helpers as a cosmetic refactor. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const r=[1,2,3,4][Symbol.iterator]().filter(x=>x%2===0).map(x=>x*10).reduce((a,v)=>a+v,0);Explained result. Filtering yields 2 and 4, mapping yields 20 and 40, and reduction returns 60. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: CCA attendance iterator. Stress-test the rule using sign-ins combined into a summary object. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “map, filter, drop and take transform consumption before reduce, so moving them changes which values and side effects participate.” Apply this procedure: Write the yielded sequence after each stage before calculating the reduction. The expected mechanism is: Filtering yields 2 and 4, mapping yields 20 and 40, and reduction returns 60. For the CCA attendance iterator, add one near-miss that exposes reordering helpers as a cosmetic refactor. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: science reading generator. Explain the rule using measurements accumulated into total and count. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “map, filter, drop and take transform consumption before reduce, so moving them changes which values and side effects participate.” Apply this procedure: Write the yielded sequence after each stage before calculating the reduction. The expected mechanism is: Filtering yields 2 and 4, mapping yields 20 and 40, and reduction returns 60. For the science reading generator, add one near-miss that exposes reordering helpers as a cosmetic refactor. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: revision-card stream. Transfer the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “map, filter, drop and take transform consumption before reduce, so moving them changes which values and side effects participate.” Apply this procedure: Write the yielded sequence after each stage before calculating the reduction. The expected mechanism is: Filtering yields 2 and 4, mapping yields 20 and 40, and reduction returns 60. For the revision-card stream, add one near-miss that exposes reordering helpers as a cosmetic refactor. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: photo metadata iterator. Predict the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “map, filter, drop and take transform consumption before reduce, so moving them changes which values and side effects participate.” Apply this procedure: Write the yielded sequence after each stage before calculating the reduction. The expected mechanism is: Filtering yields 2 and 4, mapping yields 20 and 40, and reduction returns 60. For the photo metadata iterator, add one near-miss that exposes reordering helpers as a cosmetic refactor. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers reordering helpers as a cosmetic refactor.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Write the yielded sequence after each stage before calculating the reduction.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Pipeline order changes work and meaning?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing reordering helpers as a cosmetic refactor be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny budget-entry generator with transactions folded into category balances. Include one ordinary case, one boundary and one deliberate failure caused by reordering helpers as a cosmetic refactor. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: map, filter, drop and take transform consumption before reduce, so moving them changes which values and side effects participate. It shows a trace, not only a final value. The ordinary case should demonstrate “Filtering yields 2 and 4, mapping yields 20 and 40, and reduction returns 60.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Write the yielded sequence after each stage before calculating the reduction. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Pipeline order changes work and meaning, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
CHAPTER 19 OF 20 . Transfer with judgment
19. Version support belongs in the contract
Iterator helpers are newer than long-established array methods, so deployment targets must be checked before publication. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is assuming syntax shown by one current browser exists in every school or home device. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Test typeof Iterator and the method in supported runtimes, and provide a reviewed fallback when required.
For the Version support belongs in the contract chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on assuming syntax shown by one current browser exists in every school or home device. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
const support = typeof Iterator !== 'undefined' && typeof Iterator.prototype.reduce === 'function';
console.log(support);Explained result. A supporting runtime prints true; an unsupported runtime reaches the false branch without referring to an undeclared Iterator value. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: revision-card stream. Explain the rule using confidence values reduced to a minimum. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Iterator helpers are newer than long-established array methods, so deployment targets must be checked before publication.” Apply this procedure: Test typeof Iterator and the method in supported runtimes, and provide a reviewed fallback when required. The expected mechanism is: A supporting runtime prints true; an unsupported runtime reaches the false branch without referring to an undeclared Iterator value. For the revision-card stream, add one near-miss that exposes assuming syntax shown by one current browser exists in every school or home device. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: photo metadata iterator. Transfer the rule using file sizes combined into a byte total. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Iterator helpers are newer than long-established array methods, so deployment targets must be checked before publication.” Apply this procedure: Test typeof Iterator and the method in supported runtimes, and provide a reviewed fallback when required. The expected mechanism is: A supporting runtime prints true; an unsupported runtime reaches the false branch without referring to an undeclared Iterator value. For the photo metadata iterator, add one near-miss that exposes assuming syntax shown by one current browser exists in every school or home device. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: budget-entry generator. Predict the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Iterator helpers are newer than long-established array methods, so deployment targets must be checked before publication.” Apply this procedure: Test typeof Iterator and the method in supported runtimes, and provide a reviewed fallback when required. The expected mechanism is: A supporting runtime prints true; an unsupported runtime reaches the false branch without referring to an undeclared Iterator value. For the budget-entry generator, add one near-miss that exposes assuming syntax shown by one current browser exists in every school or home device. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: project log iterator. Contrast the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “Iterator helpers are newer than long-established array methods, so deployment targets must be checked before publication.” Apply this procedure: Test typeof Iterator and the method in supported runtimes, and provide a reviewed fallback when required. The expected mechanism is: A supporting runtime prints true; an unsupported runtime reaches the false branch without referring to an undeclared Iterator value. For the project log iterator, add one near-miss that exposes assuming syntax shown by one current browser exists in every school or home device. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers assuming syntax shown by one current browser exists in every school or home device.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Test typeof Iterator and the method in supported runtimes, and provide a reviewed fallback when required.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Version support belongs in the contract?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing assuming syntax shown by one current browser exists in every school or home device be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny project log iterator with events reduced to the latest state. Include one ordinary case, one boundary and one deliberate failure caused by assuming syntax shown by one current browser exists in every school or home device. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: Iterator helpers are newer than long-established array methods, so deployment targets must be checked before publication. It shows a trace, not only a final value. The ordinary case should demonstrate “A supporting runtime prints true; an unsupported runtime reaches the false branch without referring to an undeclared Iterator value.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Test typeof Iterator and the method in supported runtimes, and provide a reviewed fallback when required. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Version support belongs in the contract, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
CHAPTER 20 OF 20 . Transfer with judgment
20. Strong tests cover seeds, emptiness, indices and closing
A reliable suite checks explicit and omitted seeds, empty and single-value cases, callback indices, source exhaustion and cleanup after errors. Treat that sentence as a testable model. A secure learner can point to the relevant input, name the operation, describe the resulting state and identify one observation that would prove the model incomplete.
The high-value mistake in this chapter is asserting only one ordinary numeric total. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. Use a probe iterator with next and return counters, then test each boundary separately.
For the Strong tests cover seeds, emptiness, indices and closing chapter on JavaScript Iterator.prototype.reduce, use a two-column trace during a short Punggol home session. On the left, write the predicted state for this exact mechanism before the tool runs. On the right, record the observation that bears on asserting only one ordinary numeric total. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.
Core worked example
console.assert([1,2,3][Symbol.iterator]().reduce((a,v)=>a+v,0)===6);Explained result. The ordinary assertion is a start; boundary tests establish the iterator-specific contract that the total alone cannot prove. Check the boundary as well as the happy path: ask what happens with an empty input, a duplicate or tied value, an unsupported type, a missing path, a NULL, or a second reference to the same object. Only the relevant boundary should be kept; the list is a prompt for judgment, not a demand to force every case into every example.
Four purposeful transfer cases
Case 1: budget-entry generator. Transfer the rule using transactions folded into category balances. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A reliable suite checks explicit and omitted seeds, empty and single-value cases, callback indices, source exhaustion and cleanup after errors.” Apply this procedure: Use a probe iterator with next and return counters, then test each boundary separately. The expected mechanism is: The ordinary assertion is a start; boundary tests establish the iterator-specific contract that the total alone cannot prove. For the budget-entry generator, add one near-miss that exposes asserting only one ordinary numeric total. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 2: project log iterator. Predict the rule using events reduced to the latest state. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A reliable suite checks explicit and omitted seeds, empty and single-value cases, callback indices, source exhaustion and cleanup after errors.” Apply this procedure: Use a probe iterator with next and return counters, then test each boundary separately. The expected mechanism is: The ordinary assertion is a start; boundary tests establish the iterator-specific contract that the total alone cannot prove. For the project log iterator, add one near-miss that exposes asserting only one ordinary numeric total. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 3: homework score stream. Contrast the rule using scores produced one at a time from a generator. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A reliable suite checks explicit and omitted seeds, empty and single-value cases, callback indices, source exhaustion and cleanup after errors.” Apply this procedure: Use a probe iterator with next and return counters, then test each boundary separately. The expected mechanism is: The ordinary assertion is a start; boundary tests establish the iterator-specific contract that the total alone cannot prove. For the homework score stream, add one near-miss that exposes asserting only one ordinary numeric total. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Case 4: library return queue. Stress-test the rule using book records folded into category counts. State the input grain or object graph, the chapter boundary and the intended output before choosing syntax. Change only one variable, so a wrong prediction has a single plausible cause.
Reasoned route. Begin with “A reliable suite checks explicit and omitted seeds, empty and single-value cases, callback indices, source exhaustion and cleanup after errors.” Apply this procedure: Use a probe iterator with next and return counters, then test each boundary separately. The expected mechanism is: The ordinary assertion is a start; boundary tests establish the iterator-specific contract that the total alone cannot prove. For the library return queue, add one near-miss that exposes asserting only one ordinary numeric total. The answer is complete only when it says why the near-miss fails and how the corrected model transfers to a different project without relying on the original variable names.
Diagnostic route
- Model check: ask the learner to draw or list the exact rows, fields, references, paths or states involved.
- Boundary check: create the smallest input that triggers asserting only one ordinary numeric total.
- Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
- Repair check: use the reversible procedure “Use a probe iterator with next and return counters, then test each boundary separately.” and record the first changed observation.
- Transfer check: repeat the rule in a second context and identify what remains invariant.
A parent does not need to know the final JavaScript Iterator.prototype.reduce syntax. For this chapter, useful prompts are: “What did you expect from Strong tests cover seeds, emptiness, indices and closing?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing asserting only one ordinary numeric total be made smaller?” The learner, not the parent, should supply the technical explanation.
Practice with an explained answer
Question. Build a tiny homework score stream with scores produced one at a time from a generator. Include one ordinary case, one boundary and one deliberate failure caused by asserting only one ordinary numeric total. Predict each result before using a tool, then report the first point where observation differs from prediction.
Answer guide. A strong response starts with the rule: A reliable suite checks explicit and omitted seeds, empty and single-value cases, callback indices, source exhaustion and cleanup after errors. It shows a trace, not only a final value. The ordinary case should demonstrate “The ordinary assertion is a start; boundary tests establish the iterator-specific contract that the total alone cannot prove.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: Use a probe iterator with next and return counters, then test each boundary separately. Other data choices are valid when the evidence supports the same causal chain.
Decision and transfer
For Strong tests cover seeds, emptiness, indices and closing, separate the documented JavaScript Iterator.prototype.reduce mechanism from the project policy. State exactly what the technical contract guarantees, then state the project choice about validation, ordering, ownership, performance or recovery. Test whether the same distinction survives one transfer case, and keep stateful experiments disposable and backed up.
Previous chapter . Contents . Next chapter
Parent guide: choose the next useful step
Start with evidence, not a label such as careless. Ask for one prediction and one trace. If the first transition is wrong, rebuild the model. If the model is sound but syntax fails, practise reference use. If routine cases are correct but boundaries fail, vary ties, defaults, unsupported inputs, ownership or missing paths. If explanations transfer, move to a small project.
Keep a weekly record with four lines: concept, prediction, observed difference and next test. Stop when fatigue replaces reasoning. A smaller case tomorrow is more useful than another hour of copying tonight.
Seek specialist help when cause and effect remain invisible after examples are reduced, when accessibility or data-loss implications are unclear, or when an important repository, database or application state may be at risk. Good support should make the learner’s reasoning more independent.
Capstone practice with explained routes
1. homework score stream: model, boundary and recovery
Create a small homework score stream using scores produced one at a time from a generator. Combine “reduce is a terminal iterator operation” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: Calling reduce repeatedly requests values until the iterator is done and returns one accumulated result. Apply: Instrument next calls and observe that the method completes before returning. Verify: The iterator is fully consumed and the returned total is 6. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.
2. library return queue: model, boundary and recovery
Create a small library return queue using book records folded into category counts. Combine “Without a seed the first value becomes the accumulator” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: When initialValue is absent, reduce takes the first iterator value as accumulator and begins callbacks with the second value at index 1. Apply: Use subtraction so the seed choice is visible. Verify: The first accumulator is 10; callbacks subtract 3 at index 1 and 2 at index 2, producing 5. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.
3. CCA attendance iterator: model, boundary and recovery
Create a small CCA attendance iterator using sign-ins combined into a summary object. Combine “One value without a seed skips the callback” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: A one-value iterator supplies its only value as accumulator and finishes before the reducer is needed. Apply: Validate values upstream or provide a seed when every value must pass through callback logic. Verify: The result is 7 and the reducer call count is zero. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.
4. science reading generator: model, boundary and recovery
Create a small science reading generator using measurements accumulated into total and count. Combine “The callback must be callable” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: A non-callable reducer causes TypeError rather than being coerced into a function. Apply: Validate the reducer boundary before consuming a stateful source. Verify: The call throws TypeError because null is not callable. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.
5. revision-card stream: model, boundary and recovery
Create a small revision-card stream using confidence values reduced to a minimum. Combine “Abrupt completion closes the iterator” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: When callback evaluation fails, the iterator-close protocol invokes a return method when present before propagating the error. Apply: Put cleanup in a generator finally block and force a reducer error. Verify: The generator prints closed because abrupt completion closes the underlying iterator. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.
6. photo metadata iterator: model, boundary and recovery
Create a small photo metadata iterator using file sizes combined into a byte total. Combine “Immutable accumulation trades allocation for clearer snapshots” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: Returning a new accumulator each step can simplify reasoning but may allocate substantially for large streams. Apply: Benchmark realistic data and choose a structure whose update cost fits the job. Verify: The final object has keys a and b, while each step created a new object. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.
7. budget-entry generator: model, boundary and recovery
Create a small budget-entry generator using transactions folded into category balances. Combine “Version support belongs in the contract” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: Iterator helpers are newer than long-established array methods, so deployment targets must be checked before publication. Apply: Test typeof Iterator and the method in supported runtimes, and provide a reviewed fallback when required. Verify: A supporting runtime prints true; an unsupported runtime reaches the false branch without referring to an undeclared Iterator value. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.
8. project log iterator: model, boundary and recovery
Create a small project log iterator using events reduced to the latest state. Combine “The reducer receives accumulator, value and index” with one later chapter. Include an ordinary case, a boundary, a deliberate failure and a recovery. Write the expected state before each operation.
Explained route. Start with: For each callback call, arguments are the current accumulator, current value and a numeric counter. Apply: Log arguments for a three-value iterator with an explicit seed. Verify: The reducer sees indices 0 and 1 because the explicit initial value makes the first element a callback value. Then add a second chapter whose boundary could change the outcome. A complete solution contains the input model, a trace, observed evidence, a correction and one transfer statement. The exact data may differ; the causal chain must be checkable.
Frequently asked questions
How long should a practice session be?
Use one complete prediction–observation–explanation cycle while attention remains good. Ten to twenty focused minutes can be enough.
Should every option or function be memorised?
No. Memorise the governing distinctions and practise retrieving the official reference. Understanding means predicting and explaining, not reciting a parameter list.
What if the result is correct but the explanation is weak?
Treat it as partial success. Ask for a trace and change one boundary. A reliable model survives controlled variation.
Is the shortest solution the best?
Not automatically. Prefer the solution whose semantics, failure modes and maintenance cost are easiest to justify for the actual project.
When should official documentation be used?
Use it whenever syntax, supported types, SQL dialect behaviour or Git version details matter. Primary documentation settles the current contract.
How can a parent help without technical expertise?
Ask what was predicted, where the first difference appeared, what evidence matters and which smaller example could isolate it.
How do we test transfer?
Change the context, vocabulary and one boundary. Require the learner to identify the invariant before using a tool.
What should be saved after practice?
Keep the corrected rule, one trace, one boundary case and the next question. Avoid storing pages of unexplained output.
Can these exercises replace backups?
No. Use disposable examples and proper backups. Learning should not endanger schoolwork, repositories or personal data.
What counts as mastery?
The learner can predict, verify, diagnose, recover and justify a choice across more than one context, while knowing when to consult the current reference.

