Skip to content

Commit

Permalink
Fix Array.sort_custom example code
Browse files Browse the repository at this point in the history
Array.sort_custom descending sort example was comparing index 0, but had expected result based on comparing index 1.  Updated to use index 1 consistently.
  • Loading branch information
aaronp64 committed Aug 26, 2024
1 parent e63c40e commit 39ca8b4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion doc/classes/Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
print(my_items) # Prints [["Rice", 4], ["Tomato", 5], ["Apple", 9]]

# Sort descending, using a lambda function.
my_items.sort_custom(func(a, b): return a[0] > b[0])
my_items.sort_custom(func(a, b): return a[1] > b[1])
print(my_items) # Prints [["Apple", 9], ["Tomato", 5], ["Rice", 4]]
[/codeblock]
It may also be necessary to use this method to sort strings by natural order, with [method String.naturalnocasecmp_to], as in the following example:
Expand Down

0 comments on commit 39ca8b4

Please sign in to comment.