From fb83d905daed6c2a7c4f95712d47815c7ccd8f2e Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 4 Feb 2021 02:02:06 +0100 Subject: Change sort_custom/bsearch_custom to use Callables --- doc/classes/Array.xml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'doc/classes') diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index de3d89ee0f..cea5360234 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -191,11 +191,9 @@ - + - - - + Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search and a custom comparison method. Optionally, a [code]before[/code] specifier can be passed. If [code]false[/code], the returned index comes after all existing entries of the value in the array. The custom method receives two arguments (an element from the array and the value searched for) and must return [code]true[/code] if the first argument is less than the second, and return [code]false[/code] otherwise. @@ -537,12 +535,10 @@ - - - + - 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]. + Sorts the array using a custom 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. [codeblocks] [gdscript] @@ -553,7 +549,7 @@ return false var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]] - my_items.sort_custom(MyCustomSorter, "sort_ascending") + my_items.sort_custom(MyCustomSorter.sort_ascending) print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]]. [/gdscript] [csharp] -- cgit v1.2.3