Data:
array1 = [{"location": "The Green Lion", "postcode": "E1 6QE"}, {"location": "Diners Inn", "postcode": "E6 5FD"}]
array2 = [{"location": "Green Lion", "postcode": "E1 6QE"}, {"location": "Diner's Inn", "postcode": "E6 5FD"}]
array3 = [{"location": "The Green Lion", "postcode": "E1 6QE"}, {"location": "Diner Inn", "postcode": "E6 5FD"}]
//array1 size - 350 | array2 size - 544 | array3 size - 88
I'm using a fuzzy comparison function to find similar elements in an array. The issue I'm facing is that my current way of achieving this involves combining the 3 arrays into 1 and for looping it twice and then fuzzy comparing location.
combined.forEach(function (x) {
combined.forEach(function (y) {
if (fuzz.token_sort_ratio(x.location, y.location) > 80) {
//Logic
}
});
});
Is there a more efficient way of achieving this instead of a nested for loop? The combined array size is 958 which means there are 917,764 iterations being ran, this doesn't seem like an efficient way of achieving this but because the value of location isn't always guaranteed to be the same, I can't use the .find() function (or can I?).
I'd recommend to create map of the locations and store results in the quadtree. Quadtree is supported by JavaScript - see
https://github.com/timohausmann/quadtree-js
I've used successfully quadtree in my practice (implemented in C++). For large datasets it appeared to be at least 10X faster than quadratic algorithm.