I have an array of 800 sentences. I want to remove all duplicates (sentences that have the same exact words, but in different order) from the array. So for example "this is a sentence" and "is this a sentence" are duplicates. Only one one of them should remain in the array (it doesn't matter which one).
My first idea was to copy them one by one to a new array, each time checking to see if the sentence already exists in the new array. I would accomplish this by looping through all the elements in the new array and using the following code for comparing the sentences:
Using jQuery to compare two arrays of Javascript objects
However, this quickly becomes too intensive in terms of calculations and causes the javascript engine to be nonresponsive.
Any ideas on how to make the algorithm more efficient would be appreciated.