Skip to content

Tag: arrays

Sorting a JS array based on an array with new indices

I can’t seem to find a neat solution to this fairly simple problem. I have an array of objects likes this: Additionally, i have an array containing new array indices that i want to apply to the above items: Meaning items[0]’s new index is 2, items[1]’s new index is 0, etc… Right now i …

How to build a Set of unique Arrays?

I want to add many arrays to a Javascript set, and ensure that only unique arrays are added to the set. However, when I try adding the same array multiple times, it is always added instead of rejected. The .has() method always returns false as well. How do I fix this? Answer I’d use a Map instead, index…