tag:blogger.com,1999:blog-16002962.post8259322337620361670..comments2023-10-13T01:00:52.135-07:00Comments on Web Jazz: Code quickie: How to interlace two arrays in rubyWil Chttp://www.blogger.com/profile/03696320260631888445noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-16002962.post-68320339644380041282013-10-29T14:42:04.438-07:002013-10-29T14:42:04.438-07:00Like ianxm wrote, that is damned sexy. Unfortunat...Like ianxm wrote, that is damned sexy. Unfortunately, if you ever had to use it with large arrays, it will slow down quite a bit. I ended up writing this as a result:<br /><br /> def interlace(other_array)<br /> if empty?<br /> other_array<br /> elsif length == other_array.length<br /> zip(other_array).flatten<br /> else<br /> l = [length, other_array.length].min<br /> (take(l).zip(other_array.take(l)) + drop(l) + other_array.drop(l)).flatten<br /> end<br /> endBrian Kiddhttps://www.blogger.com/profile/13732031661674529112noreply@blogger.comtag:blogger.com,1999:blog-16002962.post-88409453794772396462007-04-17T09:39:00.000-07:002007-04-17T09:39:00.000-07:00that is damn sexythat is damn sexyAnonymousnoreply@blogger.com