diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-01-10 21:57:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-10 21:57:28 +0100 |
commit | f39f62954eb5c9f89fb3d1e1218d5a55db0554bd (patch) | |
tree | 5cc8bcaf996013306255a7fb78f2ef0c74486bf7 /doc | |
parent | 8c24a42ea027b22567194fc0575ba4e9b4e29e6f (diff) | |
parent | 05bbbb12253022ee14ced6902c830f0c1cf60823 (diff) |
Merge pull request #34999 from cajallen/master
Updated Array's sort_custom method documentation
Diffstat (limited to 'doc')
-rw-r--r-- | doc/classes/Array.xml | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 2d330fc935..c192cee1fe 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -331,17 +331,18 @@ <argument index="1" name="func" type="String"> </argument> <description> - Sorts the array using a custom method. The arguments are an object that holds the method and the name of such method. The custom method receives two arguments (a pair of elements from the array) and must return [code]true[/code] if the first argument is less than the second, and return [code]false[/code] otherwise. + Sorts the array using a custom method. The arguments are an object that holds the method and the name of such method. The custom method receives two arguments (a pair of elements from the array) and must return either [code]true[/code] or [code]false[/code]. [b]Note:[/b] you cannot randomize the return value as the heapsort algorithm expects a deterministic result. Doing so will result in unexpected behavior. [codeblock] class MyCustomSorter: - static func sort(a, b): + static func sort_ascending(a, b): if a[0] < b[0]: return true return false var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]] - my_items.sort_custom(MyCustomSorter, "sort") + my_items.sort_custom(MyCustomSorter, "sort_ascending") + print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]] [/codeblock] </description> </method> |