Solution to @cassidoo's latest programming challenge in Ruby... not quite there as a one liner, although the logic is sound.
A more error protected and false-y returning version with some Active Support help to keep it nice and terse.
Enumerable's loveliness

A Ruby solution to Cassidy William's oddSum Interview Question

Andy Croll
After a simpler solution was suggested... I got benchmark-y.
https://andycroll.com/ruby/benchmarking-odd_sum/
Performance Testing Enumerable’s Loveliness

Benchmarking & code golfing

Andy Croll

I promise I'll stop now. But I dug even further.

Think this is my favourite solution even though it's not the fastest.

https://andycroll.com/ruby/further-options-odd_sum-with-benchmarking/

@andycroll Super fun seeing all the different ways to skin this cat, and the trade-offs between performance and readability in such a tiny microcosm.

It is unfortunate, though, that a method named `odd_sum`, doing a thing with summation, ends up calling a method called `product` 😅

@andycroll My solution would've been your first one that was just a loop. That appears to be much faster than all the Enumerable stuff:

https://gist.github.com/davetron5000/fd23514a5090f78d9ab7a358715f2fce

1_oddsum.rb

GitHub Gist: instantly share code, notes, and snippets.

Gist
@davetron5000 ...if you leave the uniq call off it does.

@andycroll The funny thing is, I don't think your solution needs .uniq at all and removing it makes it way faster than all of them.

(I changed the loop version to use a set and it was slower than yours, faster than the others)

[meanwhile in the real world, 200ms network latency to the cloud-managed DB kills the entire app 😂]

@davetron5000 @andycroll Might fiddle with Set as well.

This is purely unravelling a jumper by pulling on a thread at this point.

@andycroll just one more tweak and it'll be perfect :)
@andycroll Additional perf improvements might be to partition both arrays beforehand and use that instead of looping twice each with `select`. Might because I didn't really check.