From: Daniel Moore Date: 2008-09-20T11:14:53+09:00 Subject: Re: [QUIZ] One-Liners Mashup (#177 again) It splats an array into it's components: http://theplana.wordpress.com/2007/03/03/ruby-idioms-the-splat-operator/ . I couldn't use flatten because it would destroy nested arrays. [[1,2],[3,4]].repeat(2) => [1, 2, 1, 2, 3, 4, 3, 4] #With flatten [[1,2],[3,4]].repeat(2) => [[1, 2], [1, 2], [3, 4], [3, 4]] #Without flatten On Fri, Sep 19, 2008 at 6:53 PM, Patrick Doyle wrote: > On Fri, Sep 19, 2008 at 9:21 PM, Daniel Moore wrote: >> def repeat(i) >> r = []; each { |x| r.push(*([x] * i)) }; r >> end >> > Here's mine: > def repeat(i) > self.map {|x| [x] * i}.flatten > end > > I don't appreciate Ruby syntax enough to understand the significance > of the *(...) construct in Daniel's solution. What does that do? Can > you show an example where the results are different than my solution? > > --wpd > > -- -Daniel http://strd6.com