Module 12 · Statistical Computing and Reproducibility Lesson 115 of 120

Missing, Infinite, Invalid, and Unsupported-State Policies

Refusing to make invalid inputs look like calm markets.

2:36 clip6:12:03–6:14:40 in the full courseWatch on YouTube

Transcript

20 sentences · select one to jump there

Check your understanding

Why is the string "3" rejected in this example?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

115-missing-infinite-invalid-and-unsupported-state-policies.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 115 of 120
 * Missing, Infinite, Invalid, and Unsupported-State Policies
 * Module 12: Statistical Computing and Reproducibility
 *
 * Scenario: Refusing to make invalid inputs look like calm markets
 * Rule:     missing ≠ zero ≠ invalid ≠ unsupported
 *
 * Try it:   Why is the string "3" rejected in this example?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/statistical-computing-and-reproducibility/missing-infinite-invalid-and-unsupported-state-policies/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson115() {
  const raw:unknown[]=[1,null,NaN,Infinity,"3",-2];
  const accepted=raw.filter((x):x is number=>typeof x==="number" && Number.isFinite(x));
  const result={accepted,rejected:raw.length-accepted.length,
    sum:accepted.reduce((s,x)=>s+x,0)};
  return result;
}

export const checkedResult = {"accepted":[1,-2],"rejected":4,"sum":-1};

// Run this file directly: npx tsx lessons/12-statistical-computing-and-reproducibility/115-missing-infinite-invalid-and-unsupported-state-policies.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson115(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "accepted": [
    1,
    -2
  ],
  "rejected": 4,
  "sum": -1
}

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

missing ≠ zero ≠ invalid ≠ unsupported