Currently using JavaScript and I need to go through an array of arrays to determine if there are any duplicate arrays, and then deleting those duplicated arrays. Runtime is of the essence in this case, so I was wondering what the most EFFICIENT way of doing this is.
Is using a hash table desirable in this case? The scope of this would be to hash each sequence and then use the hash to determine whether that sequence occurs again. Hence, each sequence is an array within the master array, and any duplicates would be other arrays within the same array. Furthermore, it is extremely important that all individual arrays remain ordered themselves (i.e. the elements in the individual arrays must always keep their position). Also, all elements in the individual array are string values.
Example: Assume that there is an array A whose elements are in turn the following arrays:
A[0] = ["one", "two", "three", "four"]
A[1] = ["two", "one", "three", "four"]
A[2] = ["one", "two", "three", "four"]
In the above example, A[0] and A[2] are duplicates and so the function should return A[0] and A[1], such that there is only one instance of the same array.
forloop is enough. What are the sizes of A and A[n]?samearray, as in['one'] == ['one']; // false. you could write a function to compare them via lodash's_.isEqual- or you can use plain javascript to do it but it's not a 2-liner. especially if the real array is anything more complicated than a list of strings. if it's just strings/primitives, you could compare againstitem.join(',');