From 176a9c738fed0ed139d6971c089157bfc80b30f9 Mon Sep 17 00:00:00 2001 From: Lisandro Lorea Date: Sat, 15 Jan 2022 20:07:01 -0300 Subject: Give example of one-liner for Array natural sort The documentation for the sort method warns the user that it doesn't do natural sort but fails to provide a solution when it's just a one liner thanks to String.naturalnocasecmp_to() and lambda support This suggests exactly the same algorithm as used by the filesystem dock for file sorting. Co-authored-by: Hugo Locurcio --- doc/classes/Array.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 5b1861bc9a..7cb6f71190 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -470,6 +470,12 @@ // There is no sort support for Godot.Collections.Array [/csharp] [/codeblocks] + To perform natural order sorting, you can use [method sort_custom] with [method String.naturalnocasecmp_to] as follows: + [codeblock] + var strings = ["string1", "string2", "string10", "string11"] + strings.sort_custom(func(a, b): return a.naturalnocasecmp_to(b) < 0) + print(strings) # Prints [string1, string2, string10, string11] + [/codeblock] -- cgit v1.2.3