over 9 years ago
1> 'each' will loop through each element of the array and evaluate whatever is return inside the block, but it returns the original array without any change.
(Thus we see that whatever is written inside the each block is evaluated and the original array is returned at the end)
2>'collect' returns the new array which is created as the result of executing the specified block for every item of the given array.
(Thus we can see collect returns a new array after performing the operations defined in the block on each element of original array, leaving the original array intact)
3> 'map' is similar to 'collect'. There is no specific difference between them in functionality, both of them perform the same thing
(Thus we can see map also returns a new array after performing the operations defined in the block on each element of original array, leaving the original array intact)
0 Comment(s)