So I recently noticed that the order of you put in parameters in ruby's reduce method influenced the results.
a = ["1", "2", "3"]
a.reduce {|val, con| val + con}
a = ["123"]
However
a.reduce {|val, con| con + val}
a = ["321"]
I think it only matters how you give order to |val, con| pair, which means if con shows at the latter position, the result of every step is always gonna be stored in con. And these two should yield the same result. But obviously not here.
Anyone could provide some tips? Thanks. Any explanation of how these two methods are implemented in Ruby would hugely help.