Skip to content

Sorts strings in a human-friendly, natural ordering by treating multi-digit numbers as a single character.

Notifications You must be signed in to change notification settings

reiner-dolp/elm-natural-ordering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NaturalOrdering is an Elm-package for human-friendly sorting of lists.

Build Status Latest version of the package Status of direct dependencies Latest Elm version supported License of the package

import Html exposing (div, h3, li, text, ul)
import NaturalOrdering

main =
let
    data =
	[ "4-banana"
	, "12-apple"
	, "1-orange"
	, "2-bananb"
	]

    defaultSort =
	List.sort data

    naturalSort =
	NaturalOrdering.sort data
in
div []
    [ h3 [] [ text "Default Sort" ]
    , ul [] <| List.map (\txt -> li [] [ text txt ]) defaultSort
    , h3 [] [ text "Natural Sort" ]
    , ul [] <| List.map (\txt -> li [] [ text txt ]) naturalSort
    ]

The snippet above will output

# Default Sort

* 1-orange
* 12-apple
* 2-bananb
* 4-banana

# Natural Sort

* 1-orange
* 2-bananb
* 4-banana
* 12-apple

Run this example in your browser.

About

Sorts strings in a human-friendly, natural ordering by treating multi-digit numbers as a single character.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages