Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created January 7, 2016 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krokrob/b759edddb63592721d0a to your computer and use it in GitHub Desktop.
Save krokrob/b759edddb63592721d0a to your computer and use it in GitHub Desktop.
array = ['Michel Polnareff', 'Michel Jonasz', 'Michel Delpech', 'Maxime Leforestier']
# "Mr"
new_array = []
array.each do |singer|
new_array << "Mr #{singer}"
end
# p new_array
# MAP
# input : array
# output : array with same size
new_array = array.map do |singer|
"Mr #{singer}"
end
# p new_array
new_array.each do |singer|
puts "#{new_array.index(singer) + 1}. #{singer}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment