Ordable

Sorts the way people expect: file2 before file10, in C++, C#, Java, JavaScript, Lua, Python, and Rust.

Plain sort

    Three ways to sort a list

    Pick a list. Plain sorting compares characters one by one, so 10 lands before 9. Ordable compares numbers as numbers, and so does Intl.Collator, the browser's own, until you shuffle.

    Input:

    Case
    Compare with

    Plain sort

    list.sort()

      Ordable

      sortSmart(list)

        Intl.Collator

        numeric: true

          out of place tied with a neighbor, so its place depends on the input

          Smart keys

          Click an Ordable row. Its smart key is a string that sorts by plain comparison exactly as the row sorts in smart order. Code points in hex; 1 separates levels. A number goes in as its count of digits, then its digits, so 9 (one digit) comes before 10 (two), however they're written; the highlight marks where two keys first differ.

          Store smartKey(name) in an indexed database column and ORDER BY it, with a binary collation: the same keys come from every language.

          Play with the API

          Edit and run JavaScript using sortSmart, compareSmart, sortSmartByKey, smartKey, and Order for options. Ctrl+Enter runs it too.

          Using another language? See below for the same API in C++, C#, Java, Lua, Python, and Rust, as read-only example programs.

          
              

          Same code, seven languages

          This is the code you'd write to use Ordable from each language: one tour through the whole API. Every version prints exactly the same text, and they all run in CI.

          Run it:

          How it's made

          Ordable is written once, in Temper, a language built for writing libraries that compile to many other languages. Temper turns the same source into a natural library for each one: classes and methods in C# and Java, modules in Lua and Python, a crate in Rust, and so on. Tests run on every language, and every language sorts every list the same way.

          This page uses the JavaScript version directly, with no framework, bundled with esbuild. Much of its size is Unicode tables: digits in every script, case folding, and accented letters' base letters.