p5.js | sort() function
The sort() function in p5.js is used to sort the array elements. If the array elements are strings then it sorts them alphabetically and if the array elements are integers then it sorts them in increasing order.
Parameters: This function accepts two parameters as mentioned above and described below:
- Array: This parameter holds the array elements which to be sorted.
- Count: It holds the number of elements which need to be sorted. This should be less than the length of the array.
Return Value: It returns a new sorted array.
Below programs illustrates the sort() function in p5.js:
Example 1: This example uses sort() function to sort the array elements.
Example 2: This example uses sort() function to sort the array elements.
Example 3: This example uses sort() function to sort the array elements.