Numeric sorting & stable tie explorer
Edit numbers or scored records, compare ordering policies and see which original positions move. Switch between a copied result and an operation that rearranges its working array.
Enter numbers or scored records
Compare three declared ordering policies. Each policy starts with its own fresh working array; the editor is always preserved. The tool executes no user JavaScript.
Numbers: one decimal per line. Records: ID,score per line. At most 40 rows and 4,096 UTF-16 code units. Scores allow an optional minus, up to nine integer digits and three decimal places. No exponent, plus sign, leading zeros, headers or quoted fields. IDs: unique, case-sensitive ASCII letters, digits, underscore or hyphen, 1–32 characters. Blank lines ignored; field-edge spaces trimmed. Negative zero and numeric spelling are normalized. An empty input is valid.
Calculations run in this page. The tool does not save input, send it to a calculation service or place it in the URL. Input and results are masked from optional session recording; other page scripts and extensions are outside these guarantees. Use non-sensitive examples.
Original order
40 → 3 → 12 → 2 → 3
5 rows · numbers · copy with toSorted.
Normalized number text (UTF-16 ascending)
Returned order: 12 → 2 → 3 → 3 → 40
Working array after operation: 40 → 3 → 12 → 2 → 3
Returned array is the working array: No. Returned rows keep their original object references: Yes.
| Output position | Original position | ID | Value / score |
|---|---|---|---|
| 1 | 3 | — | 12 |
| 2 | 4 | — | 2 |
| 3 | 2 | — | 3 |
| 4 | 5 | — | 3 |
| 5 | 1 | — | 40 |
Numeric ascending; input order for ties
Returned order: 2 → 3 → 3 → 12 → 40
Working array after operation: 40 → 3 → 12 → 2 → 3
Returned array is the working array: No. Returned rows keep their original object references: Yes.
| Output position | Original position | ID | Value / score |
|---|---|---|---|
| 1 | 4 | — | 2 |
| 2 | 2 | — | 3 |
| 3 | 5 | — | 3 |
| 4 | 3 | — | 12 |
| 5 | 1 | — | 40 |
Numeric descending; input order for ties
Returned order: 40 → 12 → 3 → 3 → 2
Working array after operation: 40 → 3 → 12 → 2 → 3
Returned array is the working array: No. Returned rows keep their original object references: Yes.
| Output position | Original position | ID | Value / score |
|---|---|---|---|
| 1 | 1 | — | 40 |
| 2 | 3 | — | 12 |
| 3 | 2 | — | 3 |
| 4 | 5 | — | 3 |
| 5 | 4 | — | 2 |
Copy the sorting report
Select and copy this report for normalized input, policies, original positions and array-identity results. Integer units are divided by 1,000 to obtain displayed values.
Why 12 can appear before 2
The number example contains 40, 3, 12, 2 and another 3. Comparing normalized numeric strings produces 12, 2, 3, 3, 40; numeric ascending produces 2, 3, 3, 12, 40. The two rows with value 3 retain their input order under equal comparisons.
The text policy compares String(value) in UTF-16 order, matching default ordering for the accepted ordinary number values. This tool carries original positions in indexed row objects and supplies an explicit comparator for that policy; it does not default-sort those wrapper objects.
Stable does not mean independent of input order
Load the tied-record example. Score-only ordering yields C, B, A because B and A have equal scores and retain their incoming order. Adding ascending ASCII ID yields C, A, B. Descending score with the same ID tie rule yields A, B, C. IDs are unique here; duplicate IDs are rejected.
Copying the array does not copy its rows
Each comparison starts from a fresh working array of indexed rows. Copy mode calls native toSorted and leaves that array’s order intact. In-place mode calls native sort and returns the same working array. Both retain references to the same row objects. The input editor is never the array being rearranged, and each policy runs independently.
This is an array-identity demonstration, not a deep-clone operation. The report records reference checks and snapshots of order before and after the operation. For independent editable objects, read the structuredClone versus JSON guide.
A bounded decimal contract
Numbers and scores allow up to three decimal places and nine integer digits, with an optional minus sign. They are converted to exact integer thousandths for numeric comparisons. Output normalizes numeric spelling: 1.000 becomes 1 and -0 becomes 0. The tool accepts neither arbitrary JSON nor JavaScript, so holes, undefined, NaN, infinity, BigInt, nested records and custom comparator code are outside its input format.
ASCII ID order is for machine identifiers, not locale-aware names. The tool does not model sparse-array behavior, custom accessors, comparator side effects or implementation-specific comparator call sequences. Output positions show results, not a trace of a sorting engine’s internal calls. Native toSorted requires runtime support; an unsupported browser receives a clear error when copy mode is requested.
Continue with tested JavaScript examples
The sort versus toSorted guide includes executable examples for mutation, validation, sparse indices, comparator rules and locale-aware ordering. To check why data disappears during transport, use the JSON Lines validator for its separate record-format contract.
Technical references: Array.sort and Array.toSorted. This explorer compares declared policies on small learning inputs; it does not measure performance or certify a custom comparator.