From: Re BR Date: 2009-09-17T03:03:57+09:00 Subject: Re: string to array John@7fff.com Norman wrote: > Re BR, > > I noticed in your original statement of the problem you said the input > string was "apple-orange-grape" -- so why are you splitting on '.' in > your sample solution? > > That would be appropriate for, oh, I don't know, parts of a domain name, > but not for "apple-orange-grape" > > Re BR wrote: >> John W Higgins wrote: >>> On Wed, Sep 16, 2009 at 9:20 AM, John W Higgins >>> wrote: >>> >>>> > >>>> x = "apple-orange-grape" >>>> tmp = x.split('-') >>>> (0..tmp.length-1).map{ |i| e[i..-1].join('-') } >>>> >>> >>> Sorry that should be >>> >>> (0..tmp.length-1).map{ |i| tmp[i..-1].join('-') } >>> >>> John >> >> trying to make this as a one liner >> >> a.split('.').map{ |i| a[i..-1].join('.') } >> >> but I am missing something Hi John, I pasted the wrong line I meant to say a.split('-').map{ |i| a[i..-1].join('-') } -- Posted via http://www.ruby-forum.com/.