Understanding Line Sorting & Locale-Aware Comparisons
Sorting plain text lines requires more than simple character-code comparison. Modern browsers use the Intl.Collator and String.prototype.localeCompare() APIs to apply language-aware ordering rules that correctly handle diacritics (é, ñ, ü), ligatures, and mixed-case sequences. This prevents the notorious "uppercase-first" behavior found in naive ASCII sorts.
Natural Numeric Ordering
Lexicographic sorting (the default in most languages) places "10" before "2" because "1" comes before "2". Enabling numeric: true in localeCompare delivers natural human-friendly ordering: 1, 2, 10, 100.
Fisher-Yates Shuffling
The shuffle mode uses the Fisher-Yates (Knuth) algorithm, guaranteeing a uniformly random permutation in O(n) time. Unlike naive sort(() => Math.random() - 0.5) shuffles, it provides unbiased random ordering.
Sort Mode Applications & Examples
| Sort Mode | Input Example | Output Example | Common Use Case |
|---|---|---|---|
| Alphabetical Asc | banana, apple, cherry | apple, banana, cherry | Keyword lists, name indexes |
| Numeric / Natural | 10, 2, 100, 1 | 1, 2, 10, 100 | Product codes, file versions |
| Length Sort | short, longer, longest | short, longer, longest | Crossword puzzles, anagram solving |
| Reverse Order | 1, 2, 3, 4 | 4, 3, 2, 1 | Chronological log inversion |
| Shuffle Random | A, B, C, D | C, A, D, B | Lottery draws, testing randomization |
Frequently Asked Questions
What sorting algorithms does this tool use?
The tool uses JavaScript's native Array.prototype.sort(), which is implemented with Timsort in modern engines. It provides O(n log n) performance and stable sorting, ensuring equal elements preserve their original order.
How does natural numeric sorting work?
Natural sorting uses localeCompare with the numeric flag enabled. This ensures that "item 2" correctly sorts before "item 10", unlike naive lexicographic sorting where "10" would precede "2".
Is my text transmitted to any server?
No. Every sorting operation, shuffle pass, and deduplication cycle runs entirely within your browser's JavaScript engine via local array operations. Zero data leaves your device.
