What\'s the efficient way to multiply two arrays and get sum of multiply values in Ruby? I have two arrays in Ruby:
array_A = [1, 2, 1, 4, 5, 3, 2, 6, 5, 8, 9] a
Since speed is our primary criterion, I'm going to submit this method as it's fastest according to Peter's benchmarks.
sum, i, size = 0, 0, a1.size while i < size sum += a1[i] * a2[i] i += 1 end sum