I would like to remove orphans (non-matching pairs) from current array:
J01171 01/11/2012 08:03:34 J01171 Bath Rd Ipswich Reconnected
J01171 01/11/2012 08:04:34 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 01/11/2012 08:04:47 J01171 Bath Rd Ipswich Reconnected
J01171 02/01/2013 15:46:22 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 02/01/2013 15:46:36 J01171 Bath Rd Ipswich Reconnected
J01171 01/02/2013 18:12:43 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 01/02/2013 18:42:32 J01171 Bath Rd Ipswich Reconnected
J01181 10/12/2012 13:13:13 J01181 BathRd LeighRd Isolated by Fault
J01181 10/12/2012 15:30:01 J01181 BathRd LeighRd Reconnected
J01181 09/02/2013 00:43:00 J01181 BathRd LeighRd Isolated by OTU Fault
J01181 09/02/2013 00:47:57 J01181 BathRd LeighRd Reconnected
J01181 09/02/2013 00:49:00 J01181 BathRd LeighRd Isolated by OTU Fault
After removing orphans, the output should be like this:
J01171 01/11/2012 08:04:34 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 01/11/2012 08:04:47 J01171 Bath Rd Ipswich Reconnected
J01171 02/01/2013 15:46:22 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 02/01/2013 15:46:36 J01171 Bath Rd Ipswich Reconnected
J01171 01/02/2013 18:12:43 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 01/02/2013 18:42:32 J01171 Bath Rd Ipswich Reconnected
J01181 10/12/2012 13:13:13 J01181 BathRd LeighRd Isolated by Fault
J01181 10/12/2012 15:30:01 J01181 BathRd LeighRd Reconnected
J01181 09/02/2013 00:43:00 J01181 BathRd LeighRd Isolated by OTU Fault
J01181 09/02/2013 00:47:57 J01181 BathRd LeighRd Reconnected
All elements in a sorted array come in pairs 'Isolated - Reconnected' for all asset codes. But, the array has got orphans for some asset codes: on the top there is non-matching 'Reconnected' (because its 'Isolated' pair has been left in other log file) and at the bottom there is non-matching 'Isolated' (because its 'Reconnected' pair will be in a future log file). My task is to get rid of all orphans. I have put here only 2 asset codes, but in reality hundreds (or might be even thousands) asset codes with a half of million elements in array, therefore hundreds orphans.
Orphans may come in the middle of asset codes as well. Basically, there might be a case when three 'Isolated' will follow each other in the middle of any given asset code. I need to remove following 'Isolated'-s after the first 'Isolated', because it has not get its pair yet. For instance,
X00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated
X00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated [NEEDS TO BE REMOVED]
X00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated [NEEDS TO BE REMOVED]
X00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Reconnected
J00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated
J00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated [NEEDS TO BE REMOVED]
J00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Reconnected
J00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Reconnected [NEEDS TO BE REMOVED]
Any ideas to deal with this problem? Thanks in advance.
removeAactually do? Because if it's removing elements from the array as you are iterating over it, it could really cause problems.removeA = function(arr) { var what, a = arguments, L = a.length, ax; while (L > 1 && arr.length) { what = a[--L]; while ((ax = $.inArray(what, arr)) !== -1) { arr.splice(ax, 1); } } return arr; }