Answer the question
In order to leave comments, you need to log in
How to add only new data?
Good day.
It is necessary to display the data received by the link in json format with a certain interval.
Suppose the first request received data with id 1,2,3,4,5
The second - 3,4,5,6,7
How to add only 6 and 7 in the most kosher way without unnecessary garbage?
Thank you in advance
Answer the question
In order to leave comments, you need to log in
Solution: work with sets.
Subtract the first from the second set of id-nis. This is how the set of numbers in the second set is found, which are absent in the intersection of two sets.
I won’t give an example in JavaScript, but in Ruby it’s simple:
require 'set'
Set.new([3,4,5,6,7]) - Set.new([1,2,3,4,5])
=> #<Set: {6, 7}>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question