Last active
December 22, 2023 11:15
-
-
Save PabloAballe/84933f43e49434f8760cc75171acc55c to your computer and use it in GitHub Desktop.
Array Sorting Function: Efficient method for sorting arrays in JavaScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Array Sorting Function | |
| * Brief Description: Efficient method for sorting arrays in JavaScript. | |
| * | |
| * Author: Pablo Aballe | |
| * Date: 2023-12-22 | |
| */ | |
| /** | |
| * Sorts an array of numbers in ascending order. | |
| * @param {number[]} array - The array of numbers to sort. | |
| * @returns {number[]} - The sorted array. | |
| */ | |
| function sortArray(array) { | |
| return array.sort((a, b) => a - b); | |
| } | |
| // Usage Example | |
| console.log(sortArray([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5])); | |
| // Additional Notes: | |
| // This method uses JavaScript's sort() function, which sorts the array in place. | |
| // For sorting objects or more complex criteria, the comparison function can be adjusted. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment