[#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:6639] Re: best way to interleaf arrays?

From: cjon@... (Cullen J O'neill)
Date: 2000-11-29 16:10:02 UTC
List: ruby-talk #6639
David Alan Black (dblack@candle.superlink.net) wrote:
: 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

A somewhat different approach I thought of is:

class Array
  def intereach(arr)
    length.times { |n| yield(at(n), arr.at(n)) }
  end
end

card = [1,2,3,4]
ord = ['first','second','third','fourth']

hs = [] 
card.intereach(ord) { |n, m| hs << n << m }

hs # => [1, "first", 2, "second", 3, "third", 4, "fourth"]

Which gets the desired result.

: which is about as fast as I can get it (non-destructively :-)  

I have no idea how fast it is, but hopefully it's at least worth investigating.



--
Cullen J O'Neill
--
cjon@engin.umich.edu

In This Thread