I have an array that is very dynamic, there are new elements all the time, and other elements are removed.. The problem is that sometimes, under some circumstances, it's possible some of the elements to stay in the array forever and that is NOT what I want. Every element should be removed from the array within 15 seconds, if not, the array should remove that element automatically.
For example, in the code below, we have an array with three elements:
var array = ['e1', 'e2', 'e3'];
After 5 seconds I am adding 2 more elements in the array:
array[3] = 'e4';
array[4] = 'e5';
Now, let's say that the first 3 elements are inserted in the array in 12:00:00pm, and the second 2 elements in 12:00:05pm. I want the first 3 elements to be removed in 12:00:15pm, and the second 2 elements in 12:00:20pm......Etc....
Are there any ideas on how to solve this problem?