V
V
Victor L2017-06-01 16:17:52
JavaScript
Victor L, 2017-06-01 16:17:52

How to compare two arrays of objects and output the difference?

Greetings, there is such a task from two different databases, the rest of the goods are unloaded:

var office = [
      { name: "Карандаш", qt: 1, code: 3 },
      { name: "Ручка", qt: 20, code: 4 }
            ],
      sklad = [
    			{ name: "Карандаш", qt: 1, code: 3 },
      { name: "Ручка", qt: 3, code: 4 }
              ];

where name is the name, qt is the quantity and code is the product code, the length of the arrays is most likely not the same and will be approximately 4000-5000, the code and name should theoretically match.
It is necessary to compare and deduce the difference where something is missing, it’s not me who does the unloading processing,
1) but what requirements should I indicate to the person who will do the unloading processing?
sort by code? remove (screen) spaces and non-printable characters from the name?
2) How to catch the data that is in one array and which is not in another example
3) Are there ready-made tools (maybe you can do without bicycles)?
4) What else to pay attention to and what to consider?
5) If you have solved similar problems, share your experience and tools (what did you use)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dark Hole, 2017-06-01
@abyrkov

1. I didn't understand. If you do not know what you need from the comparison, then how can we help you? If all this will be done by a separate person, then why is there a question and generally requirements for the code?
2. Sort the array by unique data (in your case, by code or product name) and connect the elements. It's hard to explain in words, but I can try if necessary. You can try lodash, they answered another question
3. And why then questions 1 and 2? No, I don’t know similar ones, due to the fact that completely different requirements can be applied to the comparison. But, perhaps, something lodash will satisfy your requirements.
4. Pay attention to the incoherence in your question.
5. Didn't decide.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question