Skip to content

Instantly share code, notes, and snippets.

@iAnisdev
Created February 13, 2023 10:37
Show Gist options
  • Save iAnisdev/905f1ae45638adfb1e7f170561d4c2e2 to your computer and use it in GitHub Desktop.
Save iAnisdev/905f1ae45638adfb1e7f170561d4c2e2 to your computer and use it in GitHub Desktop.
Sort cards deck
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