{
  "schemaVersion": 1,
  "slug": "mode-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "c5815e503ebf83edb68f8ae4a0e8cbd666560c02de001808edcd77f88a364366",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/mode-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "mode = argmaxₓ f(x), f(x) = Σᵢ 1{xᵢ = x}",
    "vars": [
      [
        "mode",
        "most frequent value"
      ],
      [
        "f(x)",
        "frequency of x"
      ],
      [
        "x",
        "entered values"
      ],
      [
        "xᵢ",
        "i-th entered value"
      ]
    ],
    "note": "Accepts a comma-, semicolon-, or whitespace-separated list of up to 10,000 finite numbers. Empty entries and nonnumeric tokens are invalid. Every value tied for the maximum frequency is returned; if all values occur once, there is no repeated mode."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const t=String(values).trim(),num='[+-]?(?:\\\\d+(?:\\\\.\\\\d*)?|\\\\.\\\\d+)(?:[eE][+-]?\\\\d+)?',sep='(?:\\\\s*[,;]\\\\s*|\\\\s+)';if(!t||t.length>20000||!new RegExp('^\\\\s*'+num+'(?:'+sep+num+')*\\\\s*$').test(t))return{frequency:null,distinctValues:null,count:0,modeValue:null,__error:'inputError'};const xs=t.match(new RegExp(num,'g')).map(Number);if(xs.length>10000||xs.some(n=>!Number.isFinite(n)))return{frequency:null,distinctValues:null,count:0,modeValue:null,__error:'inputError'};const m=new Map();xs.forEach(n=>m.set(n,(m.get(n)||0)+1));const frequency=Math.max(...m.values()),modes=[...m].filter(([,v])=>v===frequency).map(([k])=>k).sort((a,b)=>a-b);return{frequency,distinctValues:m.size,count:xs.length,modeValue:frequency===1?'No repeated value':modes.join(', ')};",
    "inputs": [
      {
        "name": "values",
        "type": "text",
        "default": "2, 4, 4, 4, 5, 5, 7, 8, 8, 8, 9",
        "step": 1,
        "multiline": true,
        "preserveEmpty": true
      }
    ],
    "outputs": [
      {
        "name": "modeValue",
        "precision": 4,
        "unit": "",
        "type": "text",
        "display": "tokens",
        "separator": " · ",
        "numberTokens": true
      },
      {
        "name": "frequency",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "distinctValues",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "count",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      }
    ],
    "interpret": null
  }
}
