What is the difference between Array#map and Array#each?

Technology CommunityCategory: RubyWhat is the difference between Array#map and Array#each?
VietMX Staff asked 3 years ago
  • Array#each method iterates over the elements of the array and executes the provided block each time. However, it returns the original array unaffected.
  • Array#map will return a new array of elements containing the values returned by the block it is provided. It also does not affect the original array