Module 4 · Location, Ranking, and Exploratory Summaries Lesson 31 of 120

Count, Sum, Minimum, Maximum, and Range

Inspecting settlement delays before modeling them.

2:25 clip1:40:35–1:43:01 in the full courseWatch on YouTube

Transcript

20 sentences · select one to jump there

Check your understanding

Does a sum of 18 delay-hours mean the system ran for 18 hours?

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.

031-count-sum-minimum-maximum-and-range.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 031 of 120
 * Count, Sum, Minimum, Maximum, and Range
 * Module 04: Location, Ranking, and Exploratory Summaries
 *
 * Scenario: Inspecting settlement delays before modeling them
 * Rule:     count, sum, min, max, range
 *
 * Try it:   Does a sum of 18 delay-hours mean the system ran for 18 hours?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/location-ranking-and-exploratory-summaries/count-sum-minimum-maximum-and-range/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson031() {
  const hours = [1, 2, 2, 4, 9];
  const result = {count: hours.length,
    sum: hours.reduce((s,x) => s+x,0),
    min: Math.min(...hours), max: Math.max(...hours),
    range: Math.max(...hours) - Math.min(...hours)};
  return result;
}

export const checkedResult = {"count":5,"sum":18,"min":1,"max":9,"range":8};

// Run this file directly: npx tsx lessons/04-location-ranking-and-exploratory-summaries/031-count-sum-minimum-maximum-and-range.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson031(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "count": 5,
  "sum": 18,
  "min": 1,
  "max": 9,
  "range": 8
}

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

Lesson notes

The rule

count, sum, min, max, range