V
V
Viktor Arkhipov2017-10-21 09:31:10
JavaScript
Viktor Arkhipov, 2017-10-21 09:31:10

How to organize an optimal object search algorithm?

Tell me how to optimally solve this problem:
There is an object with parameters

let item = { 
    self: {
        p1: 0, p2: 1, p3: 3 
    }, 
    find: { 
        p1: 0, p2: 0, p3: 1
    } 
}

Those. it has its own state and the state it is looking for.
It is added to an array with the same objects. How now to optimally quickly find a pair for each object in the array (if any) where self parameters of one will be find parameters of another and vice versa.
Here's how this couple:
item1 = { self: { p1: 0 }, find: { p1: 1 };
item2 = { self: { p1: 1 }, find: [ p1: 0 };

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
profesor08, 2017-10-21
@profesor08

What's the problem with iterating over the entire array? Or make two other arrays self, find of the form ["013", "010"], where the states will be stored, and then search through them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question