Browse Source

Merge pull request #35801 from Calinou/array-sort-add-example

doc: Add an example for `Array.sort()`
Rémi Verschelde 5 years ago
parent
commit
188dc714b0
1 changed files with 6 additions and 1 deletions
  1. 6 1
      doc/classes/Array.xml

+ 6 - 1
doc/classes/Array.xml

@@ -322,7 +322,12 @@
 		<method name="sort">
 		<method name="sort">
 			<description>
 			<description>
 				Sorts the array.
 				Sorts the array.
-				[b]Note:[/b] strings are sorted in alphabetical, not natural order.
+				[b]Note:[/b] Strings are sorted in alphabetical order (as opposed to natural order). This may lead to unexpected behavior when sorting an array of strings ending with a sequence of numbers. Consider the following example:
+				[codeblock]
+				var strings = ["string1", "string2", "string10", "string11"]
+				strings.sort()
+				print(strings) # Prints [string1, string10, string11, string2]
+				[/codeblock]
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="sort_custom">
 		<method name="sort_custom">