- a = [ 1, 2, 3, 5, 6, 2, 3, 1, 4, 5, 4 ]
- puts a.inject( 0 ) { |c, i| c ^= i }
Find the unpaired number in an array. I can’t really think of a situation you’d need to do this, but it’s a really, really elegant solution and that’s why I’m posting it. It’s left to the reader to work out how it works. From.