55502f40dc8b7c769880b10874abc9d0

x should be ["a","c","e"] in the end. I'm looking for a one-liner, something similar to (Python's) x = [m[0] for m in M]

M = [["a", "b"], ["c", "d"], ["e", "f"]]

x = []

M.each do |m|
  x.push(m[0])
end

Refactorings

No refactoring yet !

72820eaf703cd07ba9bc6ecc09e5d81a

Alec Leitner

January 26, 2012, January 26, 2012 08:30, permalink

No rating. Login to rate!
M.map(&:first)

Your refactoring





Format Copy from initial code

or Cancel