Compare two arrays as sets
A multi-select gives you an array of ids. Deciding whether to refetch means asking whether the selection really changed — and ["a", "b"] versus ["b", "a"] is not a change, nor is ["a", "a", "b"] versus ["a", "b"].
Implement sameSet(a, b). Return true when the two arrays contain exactly the same distinct values, ignoring order and ignoring how many times each value appears, and false otherwise. Values are compared the way a Set compares them, so NaN matches NaN but 1 does not match "1". Two empty arrays are the same set. An empty array and a non-empty one are not. Never modify either input.
What it has to do
- Ignore ordering when comparing.
- Ignore duplicate values within either array.
- Return
truefor two empty arrays. - Match
NaNwithNaN, and keep1and"1"distinct. - Do not mutate either input array.
Your workspace
Ready to check it?
5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.
AI Crack & Solution Assist
Stuck? Get instant AI hints or break down the optimal solution.
Stuck? The javascript course covers everything this challenge needs.