summaryrefslogtreecommitdiff
path: root/doc/classes
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-12-09 10:03:43 +0100
committerGitHub <noreply@github.com>2017-12-09 10:03:43 +0100
commit43300bdcc2fa5aa7cf636e40a66acb43a4de834e (patch)
tree88bfd7f8c00162023d1a36b9bb05633639f19926 /doc/classes
parentb8afafa2262684ee2b451b5686679baf984c3e59 (diff)
parent9ab59343f4f5ae36d5a32e3ae943ad6671aa4df9 (diff)
Merge pull request #14432 from rminderhoud/sort_custom
Added example for Array sort_custom function [ci skip]
Diffstat (limited to 'doc/classes')
-rw-r--r--doc/classes/Array.xml10
1 files changed, 10 insertions, 0 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index a7f9a6e09c..9445a1732e 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -284,6 +284,16 @@
</argument>
<description>
Sort the array using a custom method and return reference to the array. 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 true if the first argument is less than the second, and return false otherwise. Note: 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):
+ 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")
+ [/codeblock]
</description>
</method>
</methods>