iteration

How can I check times to ensure they are in sequential order?

Hi, I've got a JSP page which allows users to enter time periods throughout a 24 hour period, they are stored as Strings from the request such as : 13:00 14:00 15:00 Whilst iterating through these values, I need to perform a check to make sure that the time in question is after the previous one, such as the above. I'm trying to av...

Performance difference between iterating once and iterating twice?

Consider something like... for (int i = 0; i < test.size(); ++i) { test[i].foo(); test[i].bar(); } Now consider.. for (int i = 0; i < test.size(); ++i) { test[i].foo(); } for (int i = 0; i < test.size(); ++i) { test[i].bar(); } Is there a large difference in time spent between these two? I.e. what is...

Iterating over multi-level ArrayObject() to print out on-screen hierarchical view

Hi, I have a ArrayObject structure that is quite complex to output, it can/and consists of multiple levels of relationship e.g. Parent -> Child -> Children -> Child etc. Structures like this are quite complex to work with when using a foreach, for or while loop. I've looked into SPL Iterators and I think this can be used. I'm a bit unf...

Are there good IList and IDictionary implementations in C# that support fail-safe iteration?

Per the title - are there good built-in options in C#/.NET for fail-safe iteration over an IList or an IDictionary? Where I'm running into problems is with code similar to the following: IList<Foo> someList = new List<Foo>(); //... foreach (Foo foo in someList) { if (foo.Bar) { someList.remove(foo); } } which throws the fol...

Objective-C Iterating through an NSString to get characters

I have this function: void myFunc(NSString* data) { NSMutableArray *instrs = [[NSMutableArray alloc] initWithCapacity:[data length]]; for (int i=0; i < [data length]; i++) { unichar c = [data characterAtIndex:i]; [instrs addObject:c]; } NSEnumerator *e = [instrs objectEnumerator]; id inst; while (...

Iterating over a JavaScript object in sort order based on particular key value of a child object

Hello all Short version: I'm looking for the JavaScript equivalent of Perl's for my $key ( sort { $hash{$a}{foo} cmp $hash{$b}{foo} } keys %hash ) { # do something with $key } More detail: I have a JSON object which consists of a bunch of other JSON objects which have identical properties to each other, like a hash of hashes in ...

jquery, IE7 and iteration

I have an array of classes and IDs and am trying to iterate through and append to those elements. The code below works in all browsers apart from IE7 and below. IE7 and below throw an exception telling me that 'length' is null or undefined. Been wrestling with it for a while now. Any ideas? Code is here: http://gist.github.com/651456 ...

how do I advance to the next item in a nested list? Python

Working with a couple of lists, iterating over each. Here's a code segment: self.links = [] self.iter=iter(self.links) for tgt in self.links: for link in self.mal_list: print(link) if tgt == link: print("Found Suspicious Link: {0}".format(tgt)) self.count += 1 else: self.coun...

jQuery.map() and iteration

I'm working my way through the O'Reilly jQuery Cookbook. On p.65 there is an example that looks wrong to me, but I'm new to jQuery (less than a week) so I figure it is very likely that I am the one who is confused. The code intends to get the first three items from an ordered list & do something with them; for simplicity's sake (on the ...

Iteratively filling an array with hashes from an each/do block gives me all repeat values..help!

I am trying to fill an array of hashes with hashes created through an each loop, If I print each individual hash within the iteration they are distinct, but when I try to push them to an array, the resulting array has the last hash repeated whatever number of times. Here's the code: def get_tweets tweet_array = Array.new tweet = {} ...