Created
October 29, 2019 02:12
-
-
Save rodurma/83c06199de847c7e834369b22e7338d8 to your computer and use it in GitHub Desktop.
Ordenando um array com sort
This file contains 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 players = [ | |
{ name: 'Rodrigo', kills: 12 }, | |
{ name: 'Vitor', kills: 9 }, | |
{ name: 'Camila', kills: 17 }, | |
{ name: 'Amanda', kills: 6 } | |
]; | |
const orderAsc = (a, b) => a.kills - b.kills; | |
const orderDesc = (a, b) => b.kills - a.kills; | |
console.log(players.sort(orderAsc)); | |
console.log(players.sort(orderDesc)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment