iterator_next.rb
a = [1,2,3,4,5,6,7,8,9,10]
a = a.map do |i|
#next if i.even?
next i if i.even?
i*10
end
p a
#=>[10, nil, 30, nil, 50, nil, 70, nil, 90, nil]
#=>[10, 2, 30, 4, 50, 6, 70, 8, 90, 10]
Go to list of users who liked
More than 5 years have passed since last update.
a = [1,2,3,4,5,6,7,8,9,10]
a = a.map do |i|
#next if i.even?
next i if i.even?
i*10
end
p a
#=>[10, nil, 30, nil, 50, nil, 70, nil, 90, nil]
#=>[10, 2, 30, 4, 50, 6, 70, 8, 90, 10]
Register as a new user and use Qiita more conveniently
Go to list of users who liked