summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-11-13 00:19:28 +0100
committerGitHub <noreply@github.com>2021-11-13 00:19:28 +0100
commit19571c9c4bb8c388ac5d9a0255a8c18c4680b7df (patch)
tree1d2319704135eea87931bff4d0acae89df757f2e /doc
parent5aae92f069b47c040d93e5edba2aad5b104fd1a5 (diff)
parentf529a58f10b11aef397c8653b693af9e10447810 (diff)
Merge pull request #54928 from KoBeWi/sorting_vegetables
Diffstat (limited to 'doc')
-rw-r--r--doc/classes/Array.xml20
1 files changed, 12 insertions, 8 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index 275b217247..b74d4c1d3d 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -477,15 +477,19 @@
[b]Note:[/b] You cannot randomize the return value as the heapsort algorithm expects a deterministic result. Doing so will result in unexpected behavior.
[codeblocks]
[gdscript]
- class MyCustomSorter:
- static func sort_ascending(a, b):
- if a[0] &lt; b[0]:
- return true
- return false
+ func sort_ascending(a, b):
+ if a[0] &lt; b[0]:
+ return true
+ return false
- var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]]
- my_items.sort_custom(MyCustomSorter.sort_ascending)
- print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]].
+ func _ready():
+ var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]]
+ my_items.sort_custom(sort_ascending)
+ print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]].
+
+ # Descending, lambda version.
+ my_items.sort_custom(func(a, b): return a[0] &gt; b[0])
+ print(my_items) # Prints [[9, Rice], [5, Potato], [4, Tomato]].
[/gdscript]
[csharp]
// There is no custom sort support for Godot.Collections.Array