Ruby Array Methods
A cheatsheet from @molly_struve regarding about working with arrays in Ruby. I thought it was awesome so decided to make this handy little paper document.

Each

[1, 2, 3].each do |number|
  puts "hi #{number}"
end

log:
hi 1
hi 2
hi 3

Map

result = [1, 2, 3, 4].map do |number|
  number + 2
end

result = [3, 4, 5, 6]

Flat Map

result = [1,2,3].flat_map do |number|
  ['a', 'b', 'c'].map do |letter|
    "#{number}:#{letter}"
  end
end

result = ["1:a", "1:b", "1:c", "2:a", "2:b", "2:c", "3:a", "3:b", "3:c"]

Select

result = [1, 2, 3, 4].select do |number|
  number.even?
end

result = [2,4]

Detect

result = [1, 2, 3, 4].detect do |number|
  number.even?
end

result = 2

Reject

result = [1, 2, 3, 4].reject do |number|
  number.even?
end

result = [1,3]

Partition

result = [1, 2, 3, 4].partition do |number|
  number.even?
end