On 10/17/05, Simon Strandgaard <neoneye / gmail.com> wrote:
> On 10/17/05, pauldacus / gmail.com <pauldacus / gmail.com> wrote:
> > Young grasshoppers... let us never forget the power of the REGEX!  Let
> > us not bother with counters or blocks... let us GSUB this bad boy!
> >
> > a = [0,1,2,3,4,5,2,3]
> >
> > a.sort.to_s.gsub(/(.)(\1)+/, '').split(//)
> >
> > =>["0", "1", "4", "5"]
>
>
> no need to sort.. :-)
>
> a = [0, 1, 2, 3, 4, 5, 2, 3]
> a.to_s.delete(a.to_s.gsub(/(.)(?!.*\1)/,'')).split('').map{|i|i.to_i}
> #=> [0, 1, 4, 5]

Both are interesting solutions, but you are returning the unique
elements of the array, not the non-unique ones, which was the original
problem. I say this not to be pedantic, but to see how you would solve
it.

Ryan