[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6586] Re: best way to interleaf arrays?

From: "Mike T. Miller" <mtm@...>
Date: 2000-11-27 01:11:37 UTC
List: ruby-talk #6586
" On Mon, 27 Nov 2000, Brian F. Feldman wrote:
" 
" > David Alan Black <dblack@candle.superlink.net> wrote:
" > > Hello --
" > > 
" > > Is there a nice Ruby idiom for interleafing arrays?  It's not hard to
" > > write a method that will do it, but I'd be interested in knowing how
" > > it's been done in the past.
" > 
" > What do you mean by interleave?  Normally I'd take this to mean that you'd 
" > want the even number of elements from the first array and the odd numbered 
" > elements to come from the second array, but it seems you're implying you 
" > just want the logical union of the two.  e.g.
" 
" Hmmmm.... I'm not sure what I said that implied that.  Maybe throwing
" in the hash thing was confusing.  Anyway, except for my misspelling
" the word (an old mental glitch), my reference was indeed to
" interleaving.
" 
" My current best shot at an interleave method is:
" 
" class Array
" 
"   def interleave(ary2)
"     a1, a2, res = self.dup, ary2.dup, []
"     res.push a1.shift, a2.shift until a1.empty? or a2.empty?
"     for n in [a1, a2]
"       res.concat n unless n.empty?
"     end
"     res
"   end
" 
" end
" 
" which is about as fast as I can get it (non-destructively :-)  

Or maybe something like this:

res = []
bigger = if a1.size > a2.size then a1 else a2
bigger.each_index { |n| res << [a1[n], a2[n]] }
res = res.flatten.compact

Of course, that only works if 'nil' is not a normal value in your
arrays.

--
Mike T. Miller
Senior Java Architect
Sun Microsystems, Switzerland
+41 1 812 04 51

In This Thread