I have an array like:
["4|23", "1", "3|10", "2"]
I want to get the sum of the odd elements, i.e. 1 + 2 = 3, perhaps with inject?
This is the response by Redis ZRANGE WITHSCORES for a sorted set. Ideally, I want to get the sum of the SCORES in a sorted set.
Thanks to everyone for your answers. All of them were really cool & enlightening.
I came up with an answer of my own. It’s pretty straightforward:
I did a performance check:
Running the script above output the following on my Mac:
Looks like my answer is the fastest. 🙂