Created
June 15, 2020 20:40
-
-
Save turbotobias/83c25172daceb4ea4edf982750b07fe4 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
| const arr = [8, 2, 5, 3, 0] | |
| arr.sort((a, b) => { | |
| // -1 sorts up | |
| if (a > b) return -1 | |
| // 1 sorts down | |
| else if (a < b) return 1 | |
| // 0 keeps position | |
| return 0 | |
| }) | |
| console.log(arr) // [8, 5, 3, 2, 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment