Created
August 9, 2021 01:06
-
-
Save hernandez87v/4ba51b27210742ccaa666f8d633dbae4 to your computer and use it in GitHub Desktop.
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
| var a = ['c', 'a', 'd', 'b', 'aa']; | |
| var b = [9, 2, 13, 7, 1, 12, 123]; | |
| // Sort in ascending lexicographical order using a built-in | |
| a.sort(); | |
| b.sort(); | |
| console.log('a:', a); | |
| console.log('b:', b); | |
| //----------------------------------------------------- | |
| var a = ['c', 'a', 'd', 'b', 'aa']; | |
| var b = [9, 2, 13, 7, 1, 12, 123]; | |
| // Sort in descending lexicographical order using a compare function | |
| a.sort(function (x, y) { | |
| return x < y; | |
| }); | |
| b.sort(function (x, y) { | |
| return x < y; | |
| }); | |
| console.log('a:', a); | |
| console.log('b:', b); | |
| //----------------------------------------------------- | |
| var a = ['c', 'a', 'd', 'b', 'aa']; | |
| // Sort in descending lexicographical order using a compare arrow function | |
| a.sort((x, y) => x < y); | |
| console.log('a:', a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment