Someone asked me how to sort the array below as per the rules of the card game using a generic method. Based on my research on the rules of card games, the small number comes first, and the names, it always arranged as Jack, Queen, King
This is the array below
const cards = ['Jack', 8, 2, 6, 'King', 5, 3, 'Queen']
Required Output
[2,3,5,6,8,'Jack','Queen','King']
So I just wrote a basic function to sort it like this
function sortCard(){
cards.sort();
console.log(cards);
}
sortCard();
It gave me the required output
[2,3,5,6,8,'Jack','Queen','King']
Though my approach is wrong and does not answer the question.
So how can I sort the card as per the rules of the card game using a generic method?