Created
February 13, 2023 10:37
-
-
Save iAnisdev/905f1ae45638adfb1e7f170561d4c2e2 to your computer and use it in GitHub Desktop.
Sort cards deck
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
let cards = ['J', 10 , 8, 2, 6, 'K', 5, 3, 'Q','A' , 7 , 4 , 9 ]; | |
// change this to match the rules of card game | |
let theRightOrder = ["A", 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K"]; | |
cards.sort((a, b) => theRightOrder.indexOf(a) - theRightOrder.indexOf(b)); | |
console.log(cards); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment