I am trying to use "reduce" to select the largest number in an array, and the specific logical judgment is written in a block. If I wrap the block in curly brackets, I get the expected result. If I wrap the block with "do..end", I get a TypeError (0 is not a symbol nor a string).
Here is the code:
p [5, 2, 9, 10, 7, 89, 70].reduce(0) { |acc, cv|
if cv > acc
acc = cv
else
acc
end
}