JavaScript Card Arrangement Challenge

Recently, I gave a full-stack interview, and the question asked from JavaScript was like this 👇 🧠 let arrangedCards = ["A", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Joker", "Queen", "King"]; The user will give you shuffled cards, like: ["King", 4, 5, "A", "Joker"] ["Queen", 7, 5, 8, "King", 2] 🎯 Interview Task: Write a JavaScript method that arranges the shuffled cards by taking reference from arrangedCards. ✅ Expected Output: ["A", 4, 5, "Joker", "King"] [2, 5, 7, 8, "Queen", "King"] #JavaScript #FullStackInterview #CodingInterview #ProblemSolving #WebDevelopment #FrontendDeveloper

You can use any sort algorithm. Just create map of cards with card name as key and index as value and then use that for sorting when looping.

Like
Reply

shuffled.sort((a, b) => arrangedCards.indexOf(a) - arrangedCards.indexOf(b)) .... this way you can solve this

Like
Reply

We sort the shuffled cards by comparing their positions in the reference arrangedCards array

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories