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
| let numbers = [4, 2, 5, 1, 3]; | |
| numbers.sort((a, b) => a - b); | |
| console.log(numbers); // [1, 2, 3, 4, 5] |
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
| let array = ['bingöl', 'ordu', 'adana']; | |
| let sortedArray = array.slice().sort(); | |
| console.log(array); // (3) ["bingöl", "ordu", "adana"] |
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
| const months = ['March', 'Jan', 'Feb', 'Dec']; | |
| months.sort(); | |
| console.log(months); | |
| // expected output: Array ["Dec", "Feb", "Jan", "March"] |
NewerOlder