Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How to Master JavaScript Array.prototype.findLast() in Punggol Tuition

Canal and bridge at Punggol Waterway Park with nearby HDB flats

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 Array.prototype.findLast(predicate, thisArg) searches an array-like object from the highest index down to zero and returns the value from the first position whose predicate result is truthy. If no position passes, it returns undefined. The method does not mutate the receiver by itself, but the callback can, and the length is captured before iteration begins. It visits integer positions in descending order, including empty slots as undefined, so mastery means predicting call order, separating a found undefined value from no match, understanding mutation timing, and choosing findLast only when the last qualifying value—not its index or every match—is the actual result needed. 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

CHAPTER 1 OF 20 . Build the model

1. Search runs from the highest index downward

Back to contents

findLast tests positions from length minus one toward zero and stops at the first truthy predicate 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 describing it as find followed by an automatic array reversal. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Search runs from the highest index downward, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Search runs from the highest index downward chapter on JavaScript Array.prototype.findLast(), 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 describing it as find followed by an automatic array reversal. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[2,7,4,9,6];
console.log(a.findLast(x=>x%2===0));

Explained result. Index 4 is tested first and value 6 passes, so earlier even values are never needed. 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 attempts. Predict the rule using the latest submitted attempt meeting a completion rule is selected. 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 “findLast tests positions from length minus one toward zero and stops at the first truthy predicate result.” Apply this procedure: State the contract for Search runs from the highest index downward, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Index 4 is tested first and value 6 passes, so earlier even values are never needed. For the homework attempts, add one near-miss that exposes describing it as find followed by an automatic array reversal. 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: reading log. Contrast the rule using the most recent session above a page threshold is found. 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 “findLast tests positions from length minus one toward zero and stops at the first truthy predicate result.” Apply this procedure: State the contract for Search runs from the highest index downward, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Index 4 is tested first and value 6 passes, so earlier even values are never needed. For the reading log, add one near-miss that exposes describing it as find followed by an automatic array reversal. 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: science readings. Stress-test the rule using the last in-range measurement is distinguished from the last array element. 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 “findLast tests positions from length minus one toward zero and stops at the first truthy predicate result.” Apply this procedure: State the contract for Search runs from the highest index downward, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Index 4 is tested first and value 6 passes, so earlier even values are never needed. For the science readings, add one near-miss that exposes describing it as find followed by an automatic array reversal. 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: CCA attendance. Explain the rule using the latest confirmed entry is selected without sorting the list. 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 “findLast tests positions from length minus one toward zero and stops at the first truthy predicate result.” Apply this procedure: State the contract for Search runs from the highest index downward, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Index 4 is tested first and value 6 passes, so earlier even values are never needed. For the CCA attendance, add one near-miss that exposes describing it as find followed by an automatic array reversal. 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 describing it as find followed by an automatic array reversal.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Search runs from the highest index downward, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Search runs from the highest index downward?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing describing it as find followed by an automatic array reversal be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny library loans with the most recent overdue record is searched by predicate. Include one ordinary case, one boundary and one deliberate failure caused by describing it as find followed by an automatic array reversal. 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: findLast tests positions from length minus one toward zero and stops at the first truthy predicate result. It shows a trace, not only a final value. The ordinary case should demonstrate “Index 4 is tested first and value 6 passes, so earlier even values are never needed.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Search runs from the highest index downward, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Search runs from the highest index downward, separate the documented JavaScript Array.prototype.findLast() 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 returned result is a value

Back to contents

findLast returns the qualifying element value, not its position. 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 using the result as though it were an array index. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for The returned result is a value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the The returned result is a value chapter on JavaScript Array.prototype.findLast(), 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 using the result as though it were an array index. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[3,8,5,8];
console.log(a.findLast(x=>x===8));

Explained result. The result is the value 8; use findLastIndex when the numeric position matters. 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: science readings. Contrast the rule using the last in-range measurement is distinguished from the last array element. 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 “findLast returns the qualifying element value, not its position.” Apply this procedure: State the contract for The returned result is a value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The result is the value 8; use findLastIndex when the numeric position matters. For the science readings, add one near-miss that exposes using the result as though it were an array index. 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: CCA attendance. Stress-test the rule using the latest confirmed entry is selected without sorting the list. 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 “findLast returns the qualifying element value, not its position.” Apply this procedure: State the contract for The returned result is a value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The result is the value 8; use findLastIndex when the numeric position matters. For the CCA attendance, add one near-miss that exposes using the result as though it were an array index. 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: family errands. Explain the rule using the last open stop in an ordered plan is located. 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 “findLast returns the qualifying element value, not its position.” Apply this procedure: State the contract for The returned result is a value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The result is the value 8; use findLastIndex when the numeric position matters. For the family errands, add one near-miss that exposes using the result as though it were an array index. 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 loans. Transfer the rule using the most recent overdue record is searched by predicate. 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 “findLast returns the qualifying element value, not its position.” Apply this procedure: State the contract for The returned result is a value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The result is the value 8; use findLastIndex when the numeric position matters. For the library loans, add one near-miss that exposes using the result as though it were an array index. 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 using the result as though it were an array index.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for The returned result is a value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from The returned result is a value?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing using the result as though it were an array index be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny test laboratory with holes, undefined, mutation, thisArg and array-like length expose boundaries. Include one ordinary case, one boundary and one deliberate failure caused by using the result as though it were an array index. 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: findLast returns the qualifying element value, not its position. It shows a trace, not only a final value. The ordinary case should demonstrate “The result is the value 8; use findLastIndex when the numeric position matters.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for The returned result is a value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For The returned result is a value, separate the documented JavaScript Array.prototype.findLast() 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 3 OF 20 . Build the model

3. No match returns undefined

Back to contents

When every predicate result is falsy, the method completes with 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 expecting null, -1 or an empty array. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for No match returns undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the No match returns undefined chapter on JavaScript Array.prototype.findLast(), 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 null, -1 or an empty array. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

console.log([1,3,5].findLast(x=>x%2===0));

Explained result. No even value passes, so the result 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: family errands. Stress-test the rule using the last open stop in an ordered plan is located. 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 every predicate result is falsy, the method completes with undefined.” Apply this procedure: State the contract for No match returns undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: No even value passes, so the result is undefined. For the family errands, add one near-miss that exposes expecting null, -1 or an empty array. 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 loans. Explain the rule using the most recent overdue record is searched by predicate. 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 every predicate result is falsy, the method completes with undefined.” Apply this procedure: State the contract for No match returns undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: No even value passes, so the result is undefined. For the library loans, add one near-miss that exposes expecting null, -1 or an empty array. 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: test laboratory. Transfer the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 every predicate result is falsy, the method completes with undefined.” Apply this procedure: State the contract for No match returns undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: No even value passes, so the result is undefined. For the test laboratory, add one near-miss that exposes expecting null, -1 or an empty array. 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: design decision. Predict the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 every predicate result is falsy, the method completes with undefined.” Apply this procedure: State the contract for No match returns undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: No even value passes, so the result is undefined. For the design decision, add one near-miss that exposes expecting null, -1 or an empty array. 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 null, -1 or an empty array.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for No match returns undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from No match returns undefined?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing expecting null, -1 or an empty array be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny design decision with findLast is compared with find, findLastIndex, filter, at, reverse and loops. Include one ordinary case, one boundary and one deliberate failure caused by expecting null, -1 or an empty array. 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 every predicate result is falsy, the method completes with undefined. It shows a trace, not only a final value. The ordinary case should demonstrate “No even value passes, so the result is undefined.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for No match returns undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For No match returns undefined, separate the documented JavaScript Array.prototype.findLast() 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. A found undefined value is ambiguous by result alone

Back to contents

An element whose value is undefined can satisfy the predicate, producing the same returned value as the no-match case. 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 checking result === undefined and concluding the predicate never matched. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for A found undefined value is ambiguous by result alone, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the A found undefined value is ambiguous by result alone chapter on JavaScript Array.prototype.findLast(), 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 checking result === undefined and concluding the predicate never matched. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[1,undefined];
const v=a.findLast(x=>x===undefined);
const i=a.findLastIndex(x=>x===undefined);
console.log(v,i);

Explained result. The value is undefined but the index is 1, proving a match occurred. 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: test laboratory. Explain the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 element whose value is undefined can satisfy the predicate, producing the same returned value as the no-match case.” Apply this procedure: State the contract for A found undefined value is ambiguous by result alone, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The value is undefined but the index is 1, proving a match occurred. For the test laboratory, add one near-miss that exposes checking result === undefined and concluding the predicate never matched. 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: design decision. Transfer the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 element whose value is undefined can satisfy the predicate, producing the same returned value as the no-match case.” Apply this procedure: State the contract for A found undefined value is ambiguous by result alone, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The value is undefined but the index is 1, proving a match occurred. For the design decision, add one near-miss that exposes checking result === undefined and concluding the predicate never matched. 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 attempts. Predict the rule using the latest submitted attempt meeting a completion rule is selected. 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 element whose value is undefined can satisfy the predicate, producing the same returned value as the no-match case.” Apply this procedure: State the contract for A found undefined value is ambiguous by result alone, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The value is undefined but the index is 1, proving a match occurred. For the homework attempts, add one near-miss that exposes checking result === undefined and concluding the predicate never matched. 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: reading log. Contrast the rule using the most recent session above a page threshold is found. 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 element whose value is undefined can satisfy the predicate, producing the same returned value as the no-match case.” Apply this procedure: State the contract for A found undefined value is ambiguous by result alone, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The value is undefined but the index is 1, proving a match occurred. For the reading log, add one near-miss that exposes checking result === undefined and concluding the predicate never matched. 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 checking result === undefined and concluding the predicate never matched.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for A found undefined value is ambiguous by result alone, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from A found undefined value is ambiguous by result alone?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing checking result === undefined and concluding the predicate never matched be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny homework attempts with the latest submitted attempt meeting a completion rule is selected. Include one ordinary case, one boundary and one deliberate failure caused by checking result === undefined and concluding the predicate never matched. 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 element whose value is undefined can satisfy the predicate, producing the same returned value as the no-match case. It shows a trace, not only a final value. The ordinary case should demonstrate “The value is undefined but the index is 1, proving a match occurred.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for A found undefined value is ambiguous by result alone, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For A found undefined value is ambiguous by result alone, separate the documented JavaScript Array.prototype.findLast() 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 5 OF 20 . Use the core tools

5. The predicate receives value, index and receiver

Back to contents

Each call gets the current value, numeric index and the original array-like object. 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 reversing parameter order and treating the index as the value. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for The predicate receives value, index and receiver, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the The predicate receives value, index and receiver chapter on JavaScript Array.prototype.findLast(), 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 reversing parameter order and treating the index as the value. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=['A','B'];
a.findLast((value,index,array)=>{console.log(value,index,array===a); return false;});

Explained result. The calls show B at index 1 and then A at index 0, with the third argument equal to a. 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 attempts. Transfer the rule using the latest submitted attempt meeting a completion rule is selected. 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 “Each call gets the current value, numeric index and the original array-like object.” Apply this procedure: State the contract for The predicate receives value, index and receiver, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The calls show B at index 1 and then A at index 0, with the third argument equal to a. For the homework attempts, add one near-miss that exposes reversing parameter order and treating the index as the 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: reading log. Predict the rule using the most recent session above a page threshold is found. 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 “Each call gets the current value, numeric index and the original array-like object.” Apply this procedure: State the contract for The predicate receives value, index and receiver, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The calls show B at index 1 and then A at index 0, with the third argument equal to a. For the reading log, add one near-miss that exposes reversing parameter order and treating the index as the 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: science readings. Contrast the rule using the last in-range measurement is distinguished from the last array element. 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 “Each call gets the current value, numeric index and the original array-like object.” Apply this procedure: State the contract for The predicate receives value, index and receiver, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The calls show B at index 1 and then A at index 0, with the third argument equal to a. For the science readings, add one near-miss that exposes reversing parameter order and treating the index as the 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: CCA attendance. Stress-test the rule using the latest confirmed entry is selected without sorting the list. 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 “Each call gets the current value, numeric index and the original array-like object.” Apply this procedure: State the contract for The predicate receives value, index and receiver, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The calls show B at index 1 and then A at index 0, with the third argument equal to a. For the CCA attendance, add one near-miss that exposes reversing parameter order and treating the index as the 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 reversing parameter order and treating the index as the value.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for The predicate receives value, index and receiver, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from The predicate receives value, index and receiver?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing reversing parameter order and treating the index as the value be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny reading log with the most recent session above a page threshold is found. Include one ordinary case, one boundary and one deliberate failure caused by reversing parameter order and treating the index as the 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: Each call gets the current value, numeric index and the original array-like object. It shows a trace, not only a final value. The ordinary case should demonstrate “The calls show B at index 1 and then A at index 0, with the third argument equal to a.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for The predicate receives value, index and receiver, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For The predicate receives value, index and receiver, separate the documented JavaScript Array.prototype.findLast() 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 6 OF 20 . Use the core tools

6. Truthiness decides a match

Back to contents

The predicate result is converted to Boolean; it need not literally be true. 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 returning an object accidentally and expecting search to continue. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Truthiness decides a match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Truthiness decides a match chapter on JavaScript Array.prototype.findLast(), 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 returning an object accidentally and expecting search to continue. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

console.log([1,2,3].findLast(x=>x===2 ? {ok:true} : 0));

Explained result. At value 2 the object is truthy, so the method returns 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: science readings. Predict the rule using the last in-range measurement is distinguished from the last array element. 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 predicate result is converted to Boolean; it need not literally be true.” Apply this procedure: State the contract for Truthiness decides a match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: At value 2 the object is truthy, so the method returns 2. For the science readings, add one near-miss that exposes returning an object accidentally and expecting search to continue. 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: CCA attendance. Contrast the rule using the latest confirmed entry is selected without sorting the list. 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 predicate result is converted to Boolean; it need not literally be true.” Apply this procedure: State the contract for Truthiness decides a match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: At value 2 the object is truthy, so the method returns 2. For the CCA attendance, add one near-miss that exposes returning an object accidentally and expecting search to continue. 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: family errands. Stress-test the rule using the last open stop in an ordered plan is located. 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 predicate result is converted to Boolean; it need not literally be true.” Apply this procedure: State the contract for Truthiness decides a match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: At value 2 the object is truthy, so the method returns 2. For the family errands, add one near-miss that exposes returning an object accidentally and expecting search to continue. 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 loans. Explain the rule using the most recent overdue record is searched by predicate. 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 predicate result is converted to Boolean; it need not literally be true.” Apply this procedure: State the contract for Truthiness decides a match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: At value 2 the object is truthy, so the method returns 2. For the library loans, add one near-miss that exposes returning an object accidentally and expecting search to continue. 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 returning an object accidentally and expecting search to continue.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Truthiness decides a match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Truthiness decides a match?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing returning an object accidentally and expecting search to continue be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny science readings with the last in-range measurement is distinguished from the last array element. Include one ordinary case, one boundary and one deliberate failure caused by returning an object accidentally and expecting search to continue. 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 predicate result is converted to Boolean; it need not literally be true. It shows a trace, not only a final value. The ordinary case should demonstrate “At value 2 the object is truthy, so the method returns 2.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Truthiness decides a match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Truthiness decides a match, separate the documented JavaScript Array.prototype.findLast() 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 7 OF 20 . Use the core tools

7. thisArg controls ordinary-function this

Back to contents

The optional second argument becomes this for a non-arrow predicate under normal call semantics. 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 thisArg to an arrow function and expecting its lexical this to change. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for thisArg controls ordinary-function this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the thisArg controls ordinary-function this chapter on JavaScript Array.prototype.findLast(), 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 thisArg to an arrow function and expecting its lexical this to change. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const rule={min:5};
console.log([3,6,4].findLast(function(x){return x>=this.min},rule));

Explained result. The ordinary function reads min from rule and returns 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: family errands. Contrast the rule using the last open stop in an ordered plan is located. 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 optional second argument becomes this for a non-arrow predicate under normal call semantics.” Apply this procedure: State the contract for thisArg controls ordinary-function this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The ordinary function reads min from rule and returns 6. For the family errands, add one near-miss that exposes passing thisArg to an arrow function and expecting its lexical this to change. 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 loans. Stress-test the rule using the most recent overdue record is searched by predicate. 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 optional second argument becomes this for a non-arrow predicate under normal call semantics.” Apply this procedure: State the contract for thisArg controls ordinary-function this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The ordinary function reads min from rule and returns 6. For the library loans, add one near-miss that exposes passing thisArg to an arrow function and expecting its lexical this to change. 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: test laboratory. Explain the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 optional second argument becomes this for a non-arrow predicate under normal call semantics.” Apply this procedure: State the contract for thisArg controls ordinary-function this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The ordinary function reads min from rule and returns 6. For the test laboratory, add one near-miss that exposes passing thisArg to an arrow function and expecting its lexical this to change. 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: design decision. Transfer the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 optional second argument becomes this for a non-arrow predicate under normal call semantics.” Apply this procedure: State the contract for thisArg controls ordinary-function this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The ordinary function reads min from rule and returns 6. For the design decision, add one near-miss that exposes passing thisArg to an arrow function and expecting its lexical this to change. 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 thisArg to an arrow function and expecting its lexical this to change.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for thisArg controls ordinary-function this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from thisArg controls ordinary-function this?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing passing thisArg to an arrow function and expecting its lexical this to change be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny CCA attendance with the latest confirmed entry is selected without sorting the list. Include one ordinary case, one boundary and one deliberate failure caused by passing thisArg to an arrow function and expecting its lexical this to change. 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 optional second argument becomes this for a non-arrow predicate under normal call semantics. It shows a trace, not only a final value. The ordinary case should demonstrate “The ordinary function reads min from rule and returns 6.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for thisArg controls ordinary-function this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For thisArg controls ordinary-function this, separate the documented JavaScript Array.prototype.findLast() 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 8 OF 20 . Use the core tools

8. Arrow functions keep lexical this

Back to contents

An arrow predicate does not receive a dynamic this binding from thisArg. 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 mixing arrow syntax with a design that depends on thisArg. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Arrow functions keep lexical this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Arrow functions keep lexical this chapter on JavaScript Array.prototype.findLast(), 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 mixing arrow syntax with a design that depends on thisArg. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const rule={min:5};
const outer=this;
[3,6].findLast((x)=>{console.log(this===outer); return x>=5},rule);

Explained result. The arrow keeps its surrounding this; capture rule directly or use an ordinary function. 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: test laboratory. Stress-test the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 arrow predicate does not receive a dynamic this binding from thisArg.” Apply this procedure: State the contract for Arrow functions keep lexical this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The arrow keeps its surrounding this; capture rule directly or use an ordinary function. For the test laboratory, add one near-miss that exposes mixing arrow syntax with a design that depends on thisArg. 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: design decision. Explain the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 arrow predicate does not receive a dynamic this binding from thisArg.” Apply this procedure: State the contract for Arrow functions keep lexical this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The arrow keeps its surrounding this; capture rule directly or use an ordinary function. For the design decision, add one near-miss that exposes mixing arrow syntax with a design that depends on thisArg. 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 attempts. Transfer the rule using the latest submitted attempt meeting a completion rule is selected. 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 arrow predicate does not receive a dynamic this binding from thisArg.” Apply this procedure: State the contract for Arrow functions keep lexical this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The arrow keeps its surrounding this; capture rule directly or use an ordinary function. For the homework attempts, add one near-miss that exposes mixing arrow syntax with a design that depends on thisArg. 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: reading log. Predict the rule using the most recent session above a page threshold is found. 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 arrow predicate does not receive a dynamic this binding from thisArg.” Apply this procedure: State the contract for Arrow functions keep lexical this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The arrow keeps its surrounding this; capture rule directly or use an ordinary function. For the reading log, add one near-miss that exposes mixing arrow syntax with a design that depends on thisArg. 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 mixing arrow syntax with a design that depends on thisArg.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Arrow functions keep lexical this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Arrow functions keep lexical this?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing mixing arrow syntax with a design that depends on thisArg be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny family errands with the last open stop in an ordered plan is located. Include one ordinary case, one boundary and one deliberate failure caused by mixing arrow syntax with a design that depends on thisArg. 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 arrow predicate does not receive a dynamic this binding from thisArg. It shows a trace, not only a final value. The ordinary case should demonstrate “The arrow keeps its surrounding this; capture rule directly or use an ordinary function.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Arrow functions keep lexical this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Arrow functions keep lexical this, separate the documented JavaScript Array.prototype.findLast() 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 9 OF 20 . Handle boundaries

9. The method is generic over array-like objects

Back to contents

findLast depends on a length and integer-indexed properties rather than on the receiver being a genuine Array. 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 converting every array-like object to an array before a simple read-only search. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for The method is generic over array-like objects, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the The method is generic over array-like objects chapter on JavaScript Array.prototype.findLast(), 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 converting every array-like object to an array before a simple read-only search. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const r=Array.prototype.findLast.call({0:'a',1:'bb',length:2},x=>x.length===1);
console.log(r);

Explained result. The search visits index 1 then 0 and returns a from the plain array-like 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: homework attempts. Explain the rule using the latest submitted attempt meeting a completion rule is selected. 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 “findLast depends on a length and integer-indexed properties rather than on the receiver being a genuine Array.” Apply this procedure: State the contract for The method is generic over array-like objects, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The search visits index 1 then 0 and returns a from the plain array-like object. For the homework attempts, add one near-miss that exposes converting every array-like object to an array before a simple read-only search. 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: reading log. Transfer the rule using the most recent session above a page threshold is found. 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 “findLast depends on a length and integer-indexed properties rather than on the receiver being a genuine Array.” Apply this procedure: State the contract for The method is generic over array-like objects, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The search visits index 1 then 0 and returns a from the plain array-like object. For the reading log, add one near-miss that exposes converting every array-like object to an array before a simple read-only search. 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: science readings. Predict the rule using the last in-range measurement is distinguished from the last array element. 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 “findLast depends on a length and integer-indexed properties rather than on the receiver being a genuine Array.” Apply this procedure: State the contract for The method is generic over array-like objects, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The search visits index 1 then 0 and returns a from the plain array-like object. For the science readings, add one near-miss that exposes converting every array-like object to an array before a simple read-only search. 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: CCA attendance. Contrast the rule using the latest confirmed entry is selected without sorting the list. 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 “findLast depends on a length and integer-indexed properties rather than on the receiver being a genuine Array.” Apply this procedure: State the contract for The method is generic over array-like objects, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The search visits index 1 then 0 and returns a from the plain array-like object. For the CCA attendance, add one near-miss that exposes converting every array-like object to an array before a simple read-only search. 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 converting every array-like object to an array before a simple read-only search.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for The method is generic over array-like objects, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from The method is generic over array-like objects?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing converting every array-like object to an array before a simple read-only search be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny library loans with the most recent overdue record is searched by predicate. Include one ordinary case, one boundary and one deliberate failure caused by converting every array-like object to an array before a simple read-only search. 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: findLast depends on a length and integer-indexed properties rather than on the receiver being a genuine Array. It shows a trace, not only a final value. The ordinary case should demonstrate “The search visits index 1 then 0 and returns a from the plain array-like object.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for The method is generic over array-like objects, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For The method is generic over array-like objects, separate the documented JavaScript Array.prototype.findLast() 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 10 OF 20 . Handle boundaries

10. Length is captured before iteration

Back to contents

The receiver length is converted once near the start, so later appends beyond that initial boundary are not added to the search. 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 pushing a new qualifying value inside the callback and expecting it to be visited. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Length is captured before iteration, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Length is captured before iteration chapter on JavaScript Array.prototype.findLast(), 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 pushing a new qualifying value inside the callback and expecting it to be visited. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[1,2];
const r=a.findLast((x,i)=>{if(i===1)a.push(99); return x===99});
console.log(r,a);

Explained result. The array gains 99, but the search range remains the original indexes 1 and 0, so r 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: science readings. Transfer the rule using the last in-range measurement is distinguished from the last array element. 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 receiver length is converted once near the start, so later appends beyond that initial boundary are not added to the search.” Apply this procedure: State the contract for Length is captured before iteration, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The array gains 99, but the search range remains the original indexes 1 and 0, so r is undefined. For the science readings, add one near-miss that exposes pushing a new qualifying value inside the callback and expecting it to be 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: CCA attendance. Predict the rule using the latest confirmed entry is selected without sorting the list. 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 receiver length is converted once near the start, so later appends beyond that initial boundary are not added to the search.” Apply this procedure: State the contract for Length is captured before iteration, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The array gains 99, but the search range remains the original indexes 1 and 0, so r is undefined. For the CCA attendance, add one near-miss that exposes pushing a new qualifying value inside the callback and expecting it to be 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: family errands. Contrast the rule using the last open stop in an ordered plan is located. 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 receiver length is converted once near the start, so later appends beyond that initial boundary are not added to the search.” Apply this procedure: State the contract for Length is captured before iteration, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The array gains 99, but the search range remains the original indexes 1 and 0, so r is undefined. For the family errands, add one near-miss that exposes pushing a new qualifying value inside the callback and expecting it to be 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 loans. Stress-test the rule using the most recent overdue record is searched by predicate. 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 receiver length is converted once near the start, so later appends beyond that initial boundary are not added to the search.” Apply this procedure: State the contract for Length is captured before iteration, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The array gains 99, but the search range remains the original indexes 1 and 0, so r is undefined. For the library loans, add one near-miss that exposes pushing a new qualifying value inside the callback and expecting it to be 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 pushing a new qualifying value inside the callback and expecting it to be visited.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Length is captured before iteration, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Length is captured before iteration?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing pushing a new qualifying value inside the callback and expecting it to be visited be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny test laboratory with holes, undefined, mutation, thisArg and array-like length expose boundaries. Include one ordinary case, one boundary and one deliberate failure caused by pushing a new qualifying value inside the callback and expecting it to be 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: The receiver length is converted once near the start, so later appends beyond that initial boundary are not added to the search. It shows a trace, not only a final value. The ordinary case should demonstrate “The array gains 99, but the search range remains the original indexes 1 and 0, so r is undefined.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Length is captured before iteration, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Length is captured before iteration, separate the documented JavaScript Array.prototype.findLast() 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 11 OF 20 . Handle boundaries

11. Sparse-array holes are visited as undefined

Back to contents

The algorithm gets every integer position in range, so an empty slot reaches the predicate with value 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 assuming findLast skips holes in the same way as some iterative array methods. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Sparse-array holes are visited as undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Sparse-array holes are visited as undefined chapter on JavaScript Array.prototype.findLast(), 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 findLast skips holes in the same way as some iterative array methods. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=Array(3); a[0]='start';
const seen=[]; a.findLast((v,i)=>{seen.push([i,v]); return false});
console.log(seen);

Explained result. Indexes 2, 1 and 0 are visited; the two holes appear to the predicate as 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: family errands. Predict the rule using the last open stop in an ordered plan is located. 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 algorithm gets every integer position in range, so an empty slot reaches the predicate with value undefined.” Apply this procedure: State the contract for Sparse-array holes are visited as undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Indexes 2, 1 and 0 are visited; the two holes appear to the predicate as undefined. For the family errands, add one near-miss that exposes assuming findLast skips holes in the same way as some iterative array methods. 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 loans. Contrast the rule using the most recent overdue record is searched by predicate. 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 algorithm gets every integer position in range, so an empty slot reaches the predicate with value undefined.” Apply this procedure: State the contract for Sparse-array holes are visited as undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Indexes 2, 1 and 0 are visited; the two holes appear to the predicate as undefined. For the library loans, add one near-miss that exposes assuming findLast skips holes in the same way as some iterative array methods. 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: test laboratory. Stress-test the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 algorithm gets every integer position in range, so an empty slot reaches the predicate with value undefined.” Apply this procedure: State the contract for Sparse-array holes are visited as undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Indexes 2, 1 and 0 are visited; the two holes appear to the predicate as undefined. For the test laboratory, add one near-miss that exposes assuming findLast skips holes in the same way as some iterative array methods. 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: design decision. Explain the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 algorithm gets every integer position in range, so an empty slot reaches the predicate with value undefined.” Apply this procedure: State the contract for Sparse-array holes are visited as undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Indexes 2, 1 and 0 are visited; the two holes appear to the predicate as undefined. For the design decision, add one near-miss that exposes assuming findLast skips holes in the same way as some iterative array methods. 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 findLast skips holes in the same way as some iterative array methods.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Sparse-array holes are visited as undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Sparse-array holes are visited as undefined?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing assuming findLast skips holes in the same way as some iterative array methods be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny design decision with findLast is compared with find, findLastIndex, filter, at, reverse and loops. Include one ordinary case, one boundary and one deliberate failure caused by assuming findLast skips holes in the same way as some iterative array methods. 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 algorithm gets every integer position in range, so an empty slot reaches the predicate with value undefined. It shows a trace, not only a final value. The ordinary case should demonstrate “Indexes 2, 1 and 0 are visited; the two holes appear to the predicate as undefined.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Sparse-array holes are visited as undefined, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Sparse-array holes are visited as undefined, separate the documented JavaScript Array.prototype.findLast() 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 12 OF 20 . Handle boundaries

12. Deleting an unvisited property changes its later value

Back to contents

Because values are retrieved as their turn arrives, deleting a lower index before it is visited can make that call observe 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 assuming every element value is snapshotted with the initial length. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Deleting an unvisited property changes its later value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Deleting an unvisited property changes its later value chapter on JavaScript Array.prototype.findLast(), 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 every element value is snapshotted with the initial length. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=['A','B','C'];
a.findLast((v,i)=>{if(i===2)delete a[0]; console.log(i,v); return false});

Explained result. When index 0 is reached, its deleted property is read as 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: test laboratory. Contrast the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 values are retrieved as their turn arrives, deleting a lower index before it is visited can make that call observe undefined.” Apply this procedure: State the contract for Deleting an unvisited property changes its later value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: When index 0 is reached, its deleted property is read as undefined. For the test laboratory, add one near-miss that exposes assuming every element value is snapshotted with the initial length. 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: design decision. Stress-test the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 values are retrieved as their turn arrives, deleting a lower index before it is visited can make that call observe undefined.” Apply this procedure: State the contract for Deleting an unvisited property changes its later value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: When index 0 is reached, its deleted property is read as undefined. For the design decision, add one near-miss that exposes assuming every element value is snapshotted with the initial length. 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 attempts. Explain the rule using the latest submitted attempt meeting a completion rule is selected. 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 values are retrieved as their turn arrives, deleting a lower index before it is visited can make that call observe undefined.” Apply this procedure: State the contract for Deleting an unvisited property changes its later value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: When index 0 is reached, its deleted property is read as undefined. For the homework attempts, add one near-miss that exposes assuming every element value is snapshotted with the initial length. 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: reading log. Transfer the rule using the most recent session above a page threshold is found. 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 values are retrieved as their turn arrives, deleting a lower index before it is visited can make that call observe undefined.” Apply this procedure: State the contract for Deleting an unvisited property changes its later value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: When index 0 is reached, its deleted property is read as undefined. For the reading log, add one near-miss that exposes assuming every element value is snapshotted with the initial length. 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 every element value is snapshotted with the initial length.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Deleting an unvisited property changes its later value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Deleting an unvisited property changes its later value?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing assuming every element value is snapshotted with the initial length be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny homework attempts with the latest submitted attempt meeting a completion rule is selected. Include one ordinary case, one boundary and one deliberate failure caused by assuming every element value is snapshotted with the initial length. 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 values are retrieved as their turn arrives, deleting a lower index before it is visited can make that call observe undefined. It shows a trace, not only a final value. The ordinary case should demonstrate “When index 0 is reached, its deleted property is read as undefined.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Deleting an unvisited property changes its later value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Deleting an unvisited property changes its later value, separate the documented JavaScript Array.prototype.findLast() 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 13 OF 20 . Debug and verify

13. Changing an unvisited value can affect the match

Back to contents

A callback mutation to a lower index may be observed when descending search reaches that index. 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 callback-side mutation as harmless because iteration order was predetermined. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Changing an unvisited value can affect the match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Changing an unvisited value can affect the match chapter on JavaScript Array.prototype.findLast(), 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 callback-side mutation as harmless because iteration order was predetermined. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[1,2,3];
const r=a.findLast((v,i)=>{if(i===2)a[1]=20; return v===20});
console.log(r);

Explained result. Index 1 is read after the mutation and yields 20, so that revised value matches. 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 attempts. Stress-test the rule using the latest submitted attempt meeting a completion rule is selected. 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 callback mutation to a lower index may be observed when descending search reaches that index.” Apply this procedure: State the contract for Changing an unvisited value can affect the match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Index 1 is read after the mutation and yields 20, so that revised value matches. For the homework attempts, add one near-miss that exposes treating callback-side mutation as harmless because iteration order was predetermined. 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: reading log. Explain the rule using the most recent session above a page threshold is found. 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 callback mutation to a lower index may be observed when descending search reaches that index.” Apply this procedure: State the contract for Changing an unvisited value can affect the match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Index 1 is read after the mutation and yields 20, so that revised value matches. For the reading log, add one near-miss that exposes treating callback-side mutation as harmless because iteration order was predetermined. 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: science readings. Transfer the rule using the last in-range measurement is distinguished from the last array element. 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 callback mutation to a lower index may be observed when descending search reaches that index.” Apply this procedure: State the contract for Changing an unvisited value can affect the match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Index 1 is read after the mutation and yields 20, so that revised value matches. For the science readings, add one near-miss that exposes treating callback-side mutation as harmless because iteration order was predetermined. 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: CCA attendance. Predict the rule using the latest confirmed entry is selected without sorting the list. 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 callback mutation to a lower index may be observed when descending search reaches that index.” Apply this procedure: State the contract for Changing an unvisited value can affect the match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: Index 1 is read after the mutation and yields 20, so that revised value matches. For the CCA attendance, add one near-miss that exposes treating callback-side mutation as harmless because iteration order was predetermined. 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 callback-side mutation as harmless because iteration order was predetermined.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Changing an unvisited value can affect the match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Changing an unvisited value can affect the match?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing treating callback-side mutation as harmless because iteration order was predetermined be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny reading log with the most recent session above a page threshold is found. Include one ordinary case, one boundary and one deliberate failure caused by treating callback-side mutation as harmless because iteration order was predetermined. 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 callback mutation to a lower index may be observed when descending search reaches that index. It shows a trace, not only a final value. The ordinary case should demonstrate “Index 1 is read after the mutation and yields 20, so that revised value matches.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Changing an unvisited value can affect the match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Changing an unvisited value can affect the match, separate the documented JavaScript Array.prototype.findLast() 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 14 OF 20 . Debug and verify

14. Shrinking length can remove later properties

Back to contents

Changing array length can delete elements below the original upper boundary, while the search still steps through the captured index range. 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 a shorter length to end the algorithm immediately. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Shrinking length can remove later properties, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Shrinking length can remove later properties chapter on JavaScript Array.prototype.findLast(), 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 a shorter length to end the algorithm immediately. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[1,2,3];
a.findLast((v,i)=>{if(i===2)a.length=1; console.log(i,v); return false});

Explained result. The algorithm still considers indexes 1 and 0, but index 1 now reads undefined after truncation. 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: science readings. Explain the rule using the last in-range measurement is distinguished from the last array element. 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 “Changing array length can delete elements below the original upper boundary, while the search still steps through the captured index range.” Apply this procedure: State the contract for Shrinking length can remove later properties, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The algorithm still considers indexes 1 and 0, but index 1 now reads undefined after truncation. For the science readings, add one near-miss that exposes expecting a shorter length to end the algorithm immediately. 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: CCA attendance. Transfer the rule using the latest confirmed entry is selected without sorting the list. 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 “Changing array length can delete elements below the original upper boundary, while the search still steps through the captured index range.” Apply this procedure: State the contract for Shrinking length can remove later properties, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The algorithm still considers indexes 1 and 0, but index 1 now reads undefined after truncation. For the CCA attendance, add one near-miss that exposes expecting a shorter length to end the algorithm immediately. 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: family errands. Predict the rule using the last open stop in an ordered plan is located. 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 “Changing array length can delete elements below the original upper boundary, while the search still steps through the captured index range.” Apply this procedure: State the contract for Shrinking length can remove later properties, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The algorithm still considers indexes 1 and 0, but index 1 now reads undefined after truncation. For the family errands, add one near-miss that exposes expecting a shorter length to end the algorithm immediately. 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 loans. Contrast the rule using the most recent overdue record is searched by predicate. 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 “Changing array length can delete elements below the original upper boundary, while the search still steps through the captured index range.” Apply this procedure: State the contract for Shrinking length can remove later properties, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The algorithm still considers indexes 1 and 0, but index 1 now reads undefined after truncation. For the library loans, add one near-miss that exposes expecting a shorter length to end the algorithm immediately. 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 a shorter length to end the algorithm immediately.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Shrinking length can remove later properties, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Shrinking length can remove later properties?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing expecting a shorter length to end the algorithm immediately be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny science readings with the last in-range measurement is distinguished from the last array element. Include one ordinary case, one boundary and one deliberate failure caused by expecting a shorter length to end the algorithm immediately. 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: Changing array length can delete elements below the original upper boundary, while the search still steps through the captured index range. It shows a trace, not only a final value. The ordinary case should demonstrate “The algorithm still considers indexes 1 and 0, but index 1 now reads undefined after truncation.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Shrinking length can remove later properties, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Shrinking length can remove later properties, separate the documented JavaScript Array.prototype.findLast() 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 predicate throws, findLast propagates the exception and does not continue to earlier positions. 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 a failing candidate to be treated as a falsy predicate result. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for An exception stops the search, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the An exception stops the search chapter on JavaScript Array.prototype.findLast(), 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 a failing candidate to be treated as a falsy predicate result. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

try{[1,2,3].findLast((x)=>{if(x===2)throw new Error('bad'); return false})}catch(e){console.log(e.message)}

Explained result. The search stops at the thrown error and prints bad. 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: family errands. Transfer the rule using the last open stop in an ordered plan is located. 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 predicate throws, findLast propagates the exception and does not continue to earlier positions.” Apply this procedure: State the contract for An exception stops the search, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The search stops at the thrown error and prints bad. For the family errands, add one near-miss that exposes expecting a failing candidate to be treated as a falsy predicate result. 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 loans. Predict the rule using the most recent overdue record is searched by predicate. 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 predicate throws, findLast propagates the exception and does not continue to earlier positions.” Apply this procedure: State the contract for An exception stops the search, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The search stops at the thrown error and prints bad. For the library loans, add one near-miss that exposes expecting a failing candidate to be treated as a falsy predicate result. 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: test laboratory. Contrast the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 predicate throws, findLast propagates the exception and does not continue to earlier positions.” Apply this procedure: State the contract for An exception stops the search, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The search stops at the thrown error and prints bad. For the test laboratory, add one near-miss that exposes expecting a failing candidate to be treated as a falsy predicate result. 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: design decision. Stress-test the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 predicate throws, findLast propagates the exception and does not continue to earlier positions.” Apply this procedure: State the contract for An exception stops the search, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The search stops at the thrown error and prints bad. For the design decision, add one near-miss that exposes expecting a failing candidate to be treated as a falsy predicate result. 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 a failing candidate to be treated as a falsy predicate result.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for An exception stops the search, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from An exception stops the search?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing expecting a failing candidate to be treated as a falsy predicate result be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny CCA attendance with the latest confirmed entry is selected without sorting the list. Include one ordinary case, one boundary and one deliberate failure caused by expecting a failing candidate to be treated as a falsy predicate result. 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 predicate throws, findLast propagates the exception and does not continue to earlier positions. It shows a trace, not only a final value. The ordinary case should demonstrate “The search stops at the thrown error and prints bad.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for An exception stops the search, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For An exception stops the search, separate the documented JavaScript Array.prototype.findLast() 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. findLast differs from find

Back to contents

find searches low-to-high, while findLast searches high-to-low; either may stop before visiting the other side. 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 sorting or reversing data when only the intended direction differs. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for findLast differs from find, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the findLast differs from find chapter on JavaScript Array.prototype.findLast(), 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 sorting or reversing data when only the intended direction differs. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[4,7,9,12];
console.log(a.find(x=>x>5),a.findLast(x=>x>5));

Explained result. find returns 7, while findLast begins at the end and returns 12. 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: test laboratory. Predict the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 “find searches low-to-high, while findLast searches high-to-low; either may stop before visiting the other side.” Apply this procedure: State the contract for findLast differs from find, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: find returns 7, while findLast begins at the end and returns 12. For the test laboratory, add one near-miss that exposes sorting or reversing data when only the intended direction differs. 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: design decision. Contrast the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 “find searches low-to-high, while findLast searches high-to-low; either may stop before visiting the other side.” Apply this procedure: State the contract for findLast differs from find, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: find returns 7, while findLast begins at the end and returns 12. For the design decision, add one near-miss that exposes sorting or reversing data when only the intended direction differs. 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 attempts. Stress-test the rule using the latest submitted attempt meeting a completion rule is selected. 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 “find searches low-to-high, while findLast searches high-to-low; either may stop before visiting the other side.” Apply this procedure: State the contract for findLast differs from find, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: find returns 7, while findLast begins at the end and returns 12. For the homework attempts, add one near-miss that exposes sorting or reversing data when only the intended direction differs. 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: reading log. Explain the rule using the most recent session above a page threshold is found. 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 “find searches low-to-high, while findLast searches high-to-low; either may stop before visiting the other side.” Apply this procedure: State the contract for findLast differs from find, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: find returns 7, while findLast begins at the end and returns 12. For the reading log, add one near-miss that exposes sorting or reversing data when only the intended direction differs. 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 sorting or reversing data when only the intended direction differs.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for findLast differs from find, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from findLast differs from find?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing sorting or reversing data when only the intended direction differs be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny family errands with the last open stop in an ordered plan is located. Include one ordinary case, one boundary and one deliberate failure caused by sorting or reversing data when only the intended direction differs. 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: find searches low-to-high, while findLast searches high-to-low; either may stop before visiting the other side. It shows a trace, not only a final value. The ordinary case should demonstrate “find returns 7, while findLast begins at the end and returns 12.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for findLast differs from find, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For findLast differs from find, separate the documented JavaScript Array.prototype.findLast() 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. findLastIndex serves position-based work

Back to contents

The related method applies the same directional predicate search but returns the index or minus one. 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 indexOf on an object result when the predicate, not identity, defines the match. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for findLastIndex serves position-based work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the findLastIndex serves position-based work chapter on JavaScript Array.prototype.findLast(), 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 indexOf on an object result when the predicate, not identity, defines the match. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[{ok:true},{ok:false},{ok:true}];
console.log(a.findLastIndex(x=>x.ok));

Explained result. The last qualifying object is at index 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: homework attempts. Contrast the rule using the latest submitted attempt meeting a completion rule is selected. 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 related method applies the same directional predicate search but returns the index or minus one.” Apply this procedure: State the contract for findLastIndex serves position-based work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The last qualifying object is at index 2. For the homework attempts, add one near-miss that exposes calling indexOf on an object result when the predicate, not identity, defines the match. 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: reading log. Stress-test the rule using the most recent session above a page threshold is found. 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 related method applies the same directional predicate search but returns the index or minus one.” Apply this procedure: State the contract for findLastIndex serves position-based work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The last qualifying object is at index 2. For the reading log, add one near-miss that exposes calling indexOf on an object result when the predicate, not identity, defines the match. 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: science readings. Explain the rule using the last in-range measurement is distinguished from the last array element. 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 related method applies the same directional predicate search but returns the index or minus one.” Apply this procedure: State the contract for findLastIndex serves position-based work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The last qualifying object is at index 2. For the science readings, add one near-miss that exposes calling indexOf on an object result when the predicate, not identity, defines the match. 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: CCA attendance. Transfer the rule using the latest confirmed entry is selected without sorting the list. 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 related method applies the same directional predicate search but returns the index or minus one.” Apply this procedure: State the contract for findLastIndex serves position-based work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The last qualifying object is at index 2. For the CCA attendance, add one near-miss that exposes calling indexOf on an object result when the predicate, not identity, defines the match. 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 indexOf on an object result when the predicate, not identity, defines the match.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for findLastIndex serves position-based work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from findLastIndex serves position-based work?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing calling indexOf on an object result when the predicate, not identity, defines the match be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny library loans with the most recent overdue record is searched by predicate. Include one ordinary case, one boundary and one deliberate failure caused by calling indexOf on an object result when the predicate, not identity, defines the match. 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 related method applies the same directional predicate search but returns the index or minus one. It shows a trace, not only a final value. The ordinary case should demonstrate “The last qualifying object is at index 2.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for findLastIndex serves position-based work, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For findLastIndex serves position-based work, separate the documented JavaScript Array.prototype.findLast() 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. filter answers a different cardinality question

Back to contents

filter evaluates the range to collect all passing values; findLast stops after the last qualifying value is known. 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 building a whole result array and taking its last item for a one-value job. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for filter answers a different cardinality question, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the filter answers a different cardinality question chapter on JavaScript Array.prototype.findLast(), 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 building a whole result array and taking its last item for a one-value job. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[1,6,3,8];
console.log(a.findLast(x=>x>5));

Explained result. The direct search returns 8 without constructing the collection of every passing element. 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: science readings. Stress-test the rule using the last in-range measurement is distinguished from the last array element. 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 “filter evaluates the range to collect all passing values; findLast stops after the last qualifying value is known.” Apply this procedure: State the contract for filter answers a different cardinality question, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The direct search returns 8 without constructing the collection of every passing element. For the science readings, add one near-miss that exposes building a whole result array and taking its last item for a one-value job. 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: CCA attendance. Explain the rule using the latest confirmed entry is selected without sorting the list. 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 “filter evaluates the range to collect all passing values; findLast stops after the last qualifying value is known.” Apply this procedure: State the contract for filter answers a different cardinality question, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The direct search returns 8 without constructing the collection of every passing element. For the CCA attendance, add one near-miss that exposes building a whole result array and taking its last item for a one-value job. 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: family errands. Transfer the rule using the last open stop in an ordered plan is located. 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 “filter evaluates the range to collect all passing values; findLast stops after the last qualifying value is known.” Apply this procedure: State the contract for filter answers a different cardinality question, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The direct search returns 8 without constructing the collection of every passing element. For the family errands, add one near-miss that exposes building a whole result array and taking its last item for a one-value job. 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 loans. Predict the rule using the most recent overdue record is searched by predicate. 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 “filter evaluates the range to collect all passing values; findLast stops after the last qualifying value is known.” Apply this procedure: State the contract for filter answers a different cardinality question, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The direct search returns 8 without constructing the collection of every passing element. For the library loans, add one near-miss that exposes building a whole result array and taking its last item for a one-value job. 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 building a whole result array and taking its last item for a one-value job.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for filter answers a different cardinality question, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from filter answers a different cardinality question?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing building a whole result array and taking its last item for a one-value job be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny test laboratory with holes, undefined, mutation, thisArg and array-like length expose boundaries. Include one ordinary case, one boundary and one deliberate failure caused by building a whole result array and taking its last item for a one-value job. 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: filter evaluates the range to collect all passing values; findLast stops after the last qualifying value is known. It shows a trace, not only a final value. The ordinary case should demonstrate “The direct search returns 8 without constructing the collection of every passing element.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for filter answers a different cardinality question, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For filter answers a different cardinality question, separate the documented JavaScript Array.prototype.findLast() 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. reverse can mutate the source

Back to contents

Array.prototype.reverse changes order in place, while findLast performs a directional read without rearranging the receiver. 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 using reverse().find(…) on data whose order other code still relies on. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for reverse can mutate the source, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the reverse can mutate the source chapter on JavaScript Array.prototype.findLast(), 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 using reverse().find(…) on data whose order other code still relies on. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const a=[1,2,3]; const r=a.findLast(x=>x<3); console.log(r,a);

Explained result. The result is 2 and the array remains in its original order. 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: family errands. Explain the rule using the last open stop in an ordered plan is located. 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 “Array.prototype.reverse changes order in place, while findLast performs a directional read without rearranging the receiver.” Apply this procedure: State the contract for reverse can mutate the source, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The result is 2 and the array remains in its original order. For the family errands, add one near-miss that exposes using reverse().find(…) on data whose order other code still relies on. 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 loans. Transfer the rule using the most recent overdue record is searched by predicate. 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 “Array.prototype.reverse changes order in place, while findLast performs a directional read without rearranging the receiver.” Apply this procedure: State the contract for reverse can mutate the source, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The result is 2 and the array remains in its original order. For the library loans, add one near-miss that exposes using reverse().find(…) on data whose order other code still relies on. 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: test laboratory. Predict the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 “Array.prototype.reverse changes order in place, while findLast performs a directional read without rearranging the receiver.” Apply this procedure: State the contract for reverse can mutate the source, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The result is 2 and the array remains in its original order. For the test laboratory, add one near-miss that exposes using reverse().find(…) on data whose order other code still relies on. 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: design decision. Contrast the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 “Array.prototype.reverse changes order in place, while findLast performs a directional read without rearranging the receiver.” Apply this procedure: State the contract for reverse can mutate the source, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The result is 2 and the array remains in its original order. For the design decision, add one near-miss that exposes using reverse().find(…) on data whose order other code still relies on. 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 using reverse().find(…) on data whose order other code still relies on.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for reverse can mutate the source, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from reverse can mutate the source?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing using reverse().find(…) on data whose order other code still relies on be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny design decision with findLast is compared with find, findLastIndex, filter, at, reverse and loops. Include one ordinary case, one boundary and one deliberate failure caused by using reverse().find(…) on data whose order other code still relies on. 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: Array.prototype.reverse changes order in place, while findLast performs a directional read without rearranging the receiver. It shows a trace, not only a final value. The ordinary case should demonstrate “The result is 2 and the array remains in its original order.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for reverse can mutate the source, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For reverse can mutate the source, separate the documented JavaScript Array.prototype.findLast() 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. Choose findLast for the last qualifying value

Back to contents

Use findLast when established order already has meaning and one final predicate match is required; choose at for a fixed last element, findLastIndex for position, filter for all matches, or a loop for richer control. 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 using findLast merely because the desired answer happens to be near the end in one sample. It matters because the output may look reasonable while the ownership, ordering, identity or safety rule is wrong. State the contract for Choose findLast for the last qualifying value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.

For the Choose findLast for the last qualifying value chapter on JavaScript Array.prototype.findLast(), 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 using findLast merely because the desired answer happens to be near the end in one sample. Explain the earliest difference with one causal sentence, then repeat only the smallest changed case.

Core worked example

const latestComplete=attempts.findLast(a=>a.submitted&&a.score!==null);

Explained result. The expression is defensible when attempt order is documented and the job is the last complete attempt 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: test laboratory. Transfer the rule using holes, undefined, mutation, thisArg and array-like length expose boundaries. 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 “Use findLast when established order already has meaning and one final predicate match is required; choose at for a fixed last element, findLastIndex for position, filter for all matches, or a loop for richer control.” Apply this procedure: State the contract for Choose findLast for the last qualifying value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The expression is defensible when attempt order is documented and the job is the last complete attempt value. For the test laboratory, add one near-miss that exposes using findLast merely because the desired answer happens to be near the end in one sample. 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: design decision. Predict the rule using findLast is compared with find, findLastIndex, filter, at, reverse and loops. 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 “Use findLast when established order already has meaning and one final predicate match is required; choose at for a fixed last element, findLastIndex for position, filter for all matches, or a loop for richer control.” Apply this procedure: State the contract for Choose findLast for the last qualifying value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The expression is defensible when attempt order is documented and the job is the last complete attempt value. For the design decision, add one near-miss that exposes using findLast merely because the desired answer happens to be near the end in one sample. 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 attempts. Contrast the rule using the latest submitted attempt meeting a completion rule is selected. 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 “Use findLast when established order already has meaning and one final predicate match is required; choose at for a fixed last element, findLastIndex for position, filter for all matches, or a loop for richer control.” Apply this procedure: State the contract for Choose findLast for the last qualifying value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The expression is defensible when attempt order is documented and the job is the last complete attempt value. For the homework attempts, add one near-miss that exposes using findLast merely because the desired answer happens to be near the end in one sample. 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: reading log. Stress-test the rule using the most recent session above a page threshold is found. 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 “Use findLast when established order already has meaning and one final predicate match is required; choose at for a fixed last element, findLastIndex for position, filter for all matches, or a loop for richer control.” Apply this procedure: State the contract for Choose findLast for the last qualifying value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. The expected mechanism is: The expression is defensible when attempt order is documented and the job is the last complete attempt value. For the reading log, add one near-miss that exposes using findLast merely because the desired answer happens to be near the end in one sample. 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 using findLast merely because the desired answer happens to be near the end in one sample.
  • Evidence check: separate a printed value from identity, ordering, ownership, type or repository state.
  • Repair check: use the reversible procedure “State the contract for Choose findLast for the last qualifying value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence.” 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 Array.prototype.findLast() syntax. For this chapter, useful prompts are: “What did you expect from Choose findLast for the last qualifying value?”, “Which state changed first?”, “What evidence tests that prediction?”, and “Can the case exposing using findLast merely because the desired answer happens to be near the end in one sample be made smaller?” The learner, not the parent, should supply the technical explanation.

Practice with an explained answer

Question. Build a tiny homework attempts with the latest submitted attempt meeting a completion rule is selected. Include one ordinary case, one boundary and one deliberate failure caused by using findLast merely because the desired answer happens to be near the end in one sample. 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: Use findLast when established order already has meaning and one final predicate match is required; choose at for a fixed last element, findLastIndex for position, filter for all matches, or a loop for richer control. It shows a trace, not only a final value. The ordinary case should demonstrate “The expression is defensible when attempt order is documented and the job is the last complete attempt value.” The boundary must exercise the same mechanism at an edge, and the deliberate failure must be repaired with: State the contract for Choose findLast for the last qualifying value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Other data choices are valid when the evidence supports the same causal chain.

Decision and transfer

For Choose findLast for the last qualifying value, separate the documented JavaScript Array.prototype.findLast() 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 attempts: model, boundary and recovery

Create a small homework attempts using the latest submitted attempt meeting a completion rule is selected. Combine “Search runs from the highest index downward” 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: findLast tests positions from length minus one toward zero and stops at the first truthy predicate result. Apply: State the contract for Search runs from the highest index downward, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: Index 4 is tested first and value 6 passes, so earlier even values are never needed. 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. reading log: model, boundary and recovery

Create a small reading log using the most recent session above a page threshold is found. Combine “A found undefined value is ambiguous by result alone” 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: An element whose value is undefined can satisfy the predicate, producing the same returned value as the no-match case. Apply: State the contract for A found undefined value is ambiguous by result alone, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The value is undefined but the index is 1, proving a match occurred. 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. science readings: model, boundary and recovery

Create a small science readings using the last in-range measurement is distinguished from the last array element. Combine “thisArg controls ordinary-function this” 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: The optional second argument becomes this for a non-arrow predicate under normal call semantics. Apply: State the contract for thisArg controls ordinary-function this, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The ordinary function reads min from rule and returns 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.

4. CCA attendance: model, boundary and recovery

Create a small CCA attendance using the latest confirmed entry is selected without sorting the list. Combine “Length is captured before iteration” 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: The receiver length is converted once near the start, so later appends beyond that initial boundary are not added to the search. Apply: State the contract for Length is captured before iteration, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The array gains 99, but the search range remains the original indexes 1 and 0, so r is undefined. 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. family errands: model, boundary and recovery

Create a small family errands using the last open stop in an ordered plan is located. Combine “Changing an unvisited value can affect the match” 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 callback mutation to a lower index may be observed when descending search reaches that index. Apply: State the contract for Changing an unvisited value can affect the match, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: Index 1 is read after the mutation and yields 20, so that revised value matches. 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. library loans: model, boundary and recovery

Create a small library loans using the most recent overdue record is searched by predicate. Combine “findLast differs from find” 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: find searches low-to-high, while findLast searches high-to-low; either may stop before visiting the other side. Apply: State the contract for findLast differs from find, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: find returns 7, while findLast begins at the end and returns 12. 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. test laboratory: model, boundary and recovery

Create a small test laboratory using holes, undefined, mutation, thisArg and array-like length expose boundaries. Combine “reverse can mutate the source” 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: Array.prototype.reverse changes order in place, while findLast performs a directional read without rearranging the receiver. Apply: State the contract for reverse can mutate the source, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The result is 2 and the array remains in its original order. 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. design decision: model, boundary and recovery

Create a small design decision using findLast is compared with find, findLastIndex, filter, at, reverse and loops. Combine “The returned result is a value” 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: findLast returns the qualifying element value, not its position. Apply: State the contract for The returned result is a value, predict one ordinary case and one boundary, run the smallest disposable test, then explain the earliest difference between prediction and evidence. Verify: The result is the value 8; use findLastIndex when the numeric position matters. 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.

Official and supporting references

Return to contents

Continue from here: Start Here · Tuition · Education · Pathways · Parenting 101 · All Site Routes

eduKate Punggol

Contact

83 Punggol Central, Singapore 828761

edu|Kate Bukit Timah

8 Fourth Avenue, Singapore 268674

By Appointment +65 8823 1234
admin@edukatesg.com

Email Us

When a child finally understands, school becomes less frightening and the future opens wider. Email us for the latest schedules and fees.

← 返回

感谢您的回复。 ✨

了解 eduKate Punggol 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读