# Array integer median

`array-integer-median` · version 1.0.0 · Numbers & math · free, no key needed

Select lower and upper middle canonical integers; emit median only for odd length.

**Use when you need to: array integer median · median of integer strings · middle values of an integer list.**

## Supported

- array integer median
- median of integer strings
- middle values of an integer list

## Not supported

- average even-length arrays
- floating-point median
- percentiles
- CSV column median

## Behavior

- values is a non-empty array of at most 10000 canonical integer strings (BigInt; -0 becomes 0).
- Values are sorted by numeric order ascending; equal values keep their original index order.
- n is the input length as a JSON integer.
- For odd n, lower, upper, and median are the sorted element at 0-based index (n-1)/2.
- For even n, lower is sorted[n/2 - 1], upper is sorted[n/2], and the median key is omitted (no averaging).
- lower, upper, and median (when present) are canonical integer strings.

## Input

- `values` (array of string, required): min items 1; max items 10000; each min length 1; each max length 1001

## Output

- `n` (integer, required): min 1; max 10000
- `lower` (string, required): pattern `^(0|-?[1-9][0-9]*)$`
- `upper` (string, required): pattern `^(0|-?[1-9][0-9]*)$`
- `median` (string, optional): pattern `^(0|-?[1-9][0-9]*)$`

## Limits

- max values: 10000
- max digits: 1000

## Example

Request input:

```json
{
  "values": [
    "9",
    "-1",
    "4"
  ]
}
```

Response:

```json
{
  "result": {
    "n": 3,
    "lower": "4",
    "upper": "4",
    "median": "4"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "array-integer-median",
  "version": "1.0.0",
  "input": {
    "values": [
      "9",
      "-1",
      "4"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/array-integer-median/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"values":["9","-1","4"]}'
```

The machine-readable contract is at [/v1/tools/array-integer-median/versions/1.0.0](/v1/tools/array-integer-median/versions/1.0.0).

### CLI

```sh
node cli.mjs run array-integer-median 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Array integer GCD](/tools/array-integer-gcd): Compute the non-negative greatest common divisor of an array of canonical integer strings.
- [Array integer LCM](/tools/array-integer-lcm): Compute the non-negative least common multiple of an array of canonical integer strings.
- [Array integer cumulative sum](/tools/array-integer-cumulative-sum): Replace an array of canonical integer strings with equal-length prefix sums.
- [Array integer mode](/tools/array-integer-mode): Return the most frequent canonical integers, listing every mode in first-seen order.
- [Array integer product](/tools/array-integer-product): Multiply an array of canonical integer strings and return the canonical product.
- [Array rational sum](/tools/array-rational-sum): Sum an array of canonical rationals and return the reduced total.
