How to implement equivalence among arrays in JavaScript? How to enumerate and count each equivalence class?

I find myself genuinely intrigued by how the JavaScript community addresses fundamental challenges, ranging from object equivalence to the formal evaluation of expressions.

At the moment, I’m exploring a unified, queue-based pattern that aims to address a variety of challenges. You can take a look at my work on classifier.js.

I would be very interested in comparing the effectiveness of this pattern against the established methods prevalent within the JavaScript community. My nickname, ‘challenger’ is intended to reflect such an aspiration.

I would start with a fundamental concept: equivalence among objects in its simplest form—specifically, the equivalence among flattened arrays.

Consider an iteration of flattened arrays:

const 
        DATA = [[1, 0], [0, 1], [0], [0]]

Suppose you aim to establish equivalence by value among them. This means that arrays sharing the same values should not be duplicated. Additionally, you might want to tally the occurrences of each array and potentially enumerate all arrays sharing certain components. In the provided example:

  • the arrays are: [1, 0], [0, 1], [0]
  • the number of occurrences of the array [0] is 2
  • the set of arrays having 0 as first component is [0], [0, 1].

How would one go about implementing these functionalities? Could you provide a script to accomplish this?