eksperimental
Natural Sorting algorithms
Hi,
we are trying to sort things naturally in ExDoc.
Can anybody recommend a natural sorting algorithm implementation in Elixir?
I have a a few but I am looking for options,
Thank you.
Most Liked
mudasobwa
FWIW, I have proposed the custom optimized sorter: Sort items "naturally" in menu, summary, function list, etc. · Issue #1440 · elixir-lang/ex_doc · GitHub
adkron
We updated NaturalSort with changes from @eksperimental. Thanks for fixing those bugs.
Sebb
How do you define “natural”?
Things that come to mind:
- ignore case
- ignore diacritics
2 < 10
sabiwara
I have this hacky solution which should work but probably isn’t optimal:
Enum.sort_by(~w(A B a b), &{String.downcase(&1), &1})
eksperimental
EDIT: the implementation is correct, I had the wrong input
The problem with this approach is that it returns different results depending on the initial order for the same list shuffled.
iex(16)> Enum.sort_by(~w(A B a b), &{String.downcase(&1), &1})
["A", "a", "B", "b"]
iex(17)> Enum.sort_by(~w(a B B b), &{String.downcase(&1), &1})
["a", "B", "B", "b"]
~~Actually I have reported this very same issue to this library just a few hours ago: Issues · BinaryNoggin/natural_order · GitHub







