zaagan
12/29/2019 - 8:33 AM

Ruby Basis - Map vs Each

Ruby Basis - Map vs Each

# map vs each
prices = [2, 3, 4, 5, 6, 7, 8, 9]

using_each =  prices.each{ |x| x + 2 }
using_map =  prices.map{ |x| x + 2 }

p  'Using each : ' + using_each.to_s
# Output > [2, 3, 4, 5, 6, 7, 8, 9]

p  'Using map : ' + using_map.to_s
# Output > [4, 5, 6, 7, 8, 9, 10, 11]