Ruby
Array parsing in a block
M = [["a", "b"], ["c", "d"], ["e", "f"]]
x = []
M.each do |m|
x.push(m[0])
end
M = [["a", "b"], ["c", "d"], ["e", "f"]]
x = []
M.each do |m|
x.push(m[0])
end
Refactorings
No refactoring yet !
January 26, 2012,
January 26, 2012 08:30,
permalink
No rating.
Login to rate!
M.map(&:first)
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]