Discovering common elements in various arrays of objects

Details:

record1 = [{"site": "The Blue Tiger", "zipcode": "E1 6QE"}, {"site": "Cafe Deluxe", "zipcode": "E6 5FD"}]
record2 = [{"site": "Blue Tiger", "zipcode": "E1 6QE"}, {"site": "Deluxe Cafe", "zipcode": "E6 5FD"}]
record3 = [{"site": "The Blue Tiger", "zipcode": "E1 6QE"}, {"site": "Deluxe Café", "zipcode": "E6 5FD"}]
//record1 size - 350 | record2 size - 544 | record3 size - 88

I am utilizing a fuzzy matching function to identify similar elements in the records. Currently, I merge the 3 records into one array, iterate through it twice with nested loops, and then perform fuzzy comparisons on the site field.

merged.forEach(function (a) {
        merged.forEach(function (b) {
            if (fuzz.token_sort_ratio(a.site, b.site) > 80) {
                //Actions 
            }
        });
    });

Is there a more efficient approach for this task rather than using nested loops? The total size of the combined array is 958, leading to 917,764 iterations, which doesn't seem optimal. However, due to the unpredictable nature of the site values, using the .find() function may not be suitable. Any suggestions?

Answer №1

To optimize the process, consider creating a map of locations and storing the results in a quadtree data structure. JavaScript supports the use of quadtree - check out https://github.com/timohausmann/quadtree-js

I have personally utilized quadtree successfully in my work (implemented in C++). When dealing with large datasets, it proved to be at least 10 times faster than a quadratic algorithm.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing the output from a console.log in a webpage

Although the function I created is functioning properly and successfully outputs the value to my terminal onSubmit, I am facing difficulty in understanding why this code isn't updating my html. router.post('/index', function(req, res, next) ...

Instructions on calculating the sum of a checkbox value and a textbox value

Here, my goal is to dynamically calculate the total value of selected checkboxes (Checkbox1 and Checkbox3) with the value in TextBox1, and then display the sum in TextBox2 without the need for any button click event. <div> <asp:Tex ...

Looking to get an object from a child process's stdout?

I am working on running a process on a different instance than the Node server. To achieve this, I have created a loop and executed the child_process. The data retrieved from the child_process is in object format as shown below. { data: [], status: &apos ...

Locate all records in Mongoose that do not have a specific value (using the $ne operator)

In my mongoose query, I am facing an issue where I need to select all rows except for specific ids. Here is a snippet of my code: var ids = [{id: 123},{id: 222},{id:333}]; User.find({_id: {$ne: ids.id }},'firstName lastName _id avatar',functi ...

Tips for maintaining the state in a React class component for the UI while navigating or refreshing the page

Is there a way to persist the selection stored in state even after page navigation? I have heard that using local storage is a possible solution, which is my preferred method. However, I have only found resources for implementing this in functional compone ...

Unleashing the full power of Node.JS asynchronous operations

I've been struggling to grasp how to effectively manage the asynchronous nature of Node.JS. Despite reading extensively on the topic and experimenting with message passing and callback functions, I can't seem to get my object constructor to load ...

Error when compiling TypeScript: The callback function provided in Array.map is not callable

This is a Node.js API that has been written in Typescript. app.post('/photos/upload', upload.array('photos', 12), async (req, res) => { var response = { } var list = [] try { const col = await loadCollection(COLLECTION_NAM ...

What is the best way to update the displayed data when using Mobx with an observable array?

Is there a way to re-render observable array data in Mobx? I have used the observer decorator in this class. interface IQuiz { quizProg: TypeQuizProg; qidx: number; state: IStateCtx; actions: IActionsCtx; } @observer class Comp extends Rea ...

Ensuring JS consistently monitors changes in value

Is there an equivalent of (void update) in Unity that is called every frame in Web Development (using JavaScript)? "I want it to continuously check if certain values have changed and then update them accordingly." let governmentprice = parseFloat(select ...

What is the method for accessing an anonymous function within a JavaScript Object?

Currently facing an issue with a Node.js package called Telegraf, which is a bot framework. The problem arises when trying to create typings for it in TypeScript. The package exports the following: module.exports = Object.assign(Telegraf, { Composer, ...

Error: Trying to access properties of an undefined object (specifically 'promise.data.map')

Currently, I am in the process of writing unit tests for a project built with Angular version 1.2. For my controller tests, I have set up a mockService that returns a deferred promise. One of the service methods looks like this: function getItems() { ...

Deploy NextJs on an IIS server

Greetings! I have a colleague who has a node.js (next.js) website that runs smoothly when built and started through the console (npm run build and npm start). We have now hosted it on an Azure VM (Windows Server 2016 IIS, with iisnode and urlrewrite inst ...

Is it recommended to exclude the NGXS NgxsLoggerPluginModule for production deployments?

When developing, it's common to use the following imports: import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin'; import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; Is it recommended to remove these imp ...

Unraveling the complexities of parsing multi-tiered JSON structures

I am struggling with indexing values from a multi-level JSON array. Here is the JSON data in question: { "items": [ { "snippet": { "title": "YouTube Developers Live: Embedded Web Player Customization" } ...

Having trouble accessing req.user on my Node.js server using Auth0 and Angular

Currently, I am utilizing auth0 for my admin panel's login system and it is functioning smoothly. However, I have encountered an issue in node where 'req.user' is returning as undefined for some unknown reason. This setup is fairly basic; I ...

Is it possible to convert a type to a JSON file programmatically?

Recently, I have been tasked with implementing configuration files for my system, one for each environment. However, when it came time to use the config, I realized that it was not typed in an easy way. To solve this issue, I created an index file that imp ...

JavaScript has been used to modify a cell's URL in jqGrid

Currently, I am utilizing struts2-jqgrid along with JavaScript. After the jqgrid has finished loading, it retrieves <s:url var="updateurl" action="pagosActualizar"/>. Subsequently, in the HTML view source, jqgrid generates options_gridtable.cellurl = ...

Outdated jQuery script no longer functioning (Wordpress)

I recently updated a WordPress site to Version 5.7.2 and now two of the custom Metaboxes are not functioning as expected. The issue seems to be related to the outdated jQuery version used by the Metaboxes. To address this problem, I installed a Plugin cal ...

axios: prevent automatic sorting of objects according to keys

When using axios, I am receiving an API response. To send the sorted API response based on name, I use the following endpoint: http://localhost:8000/api/ingredients/ordering=name The actual object received from my server looks like this: { 2:{"id":2 ...

What is the source of the compiler options in tsconfig.json?

Currently utilizing Typescript in NestJs, I have incorporated various packages. However, the specific package responsible for altering these settings remains unknown to me: "checkJs": false, "skipLibCheck": true Is there a method to ...