I am trying to understand what is a semantically right way to use map
. As map
can behave the same way as each
, you could modify the array any way you like. But I've been told by my colleague that after map
is applied, array should have
the same order and the same size.
For example, that would mean using the map to return an updated array won't be the right way to use map
:
array = [1,2,3,4]
array.map{|num| num unless num == 2 || num == 4}.compact
I've been using map
and other Enumerator
methods for ages and never thought about this too much. Would appreciate advice from experienced Ruby Developers.