You are viewing a single comment's thread. Return to all comments →
Solution 1 :
arr = [] animals.each_with_index { |item, index| arr.push( "#{index}:#{item}" ) unless index < skip } arr
Solution 2 : animals.map.with_index { |item, index| ( "#{index}:#{item}" ) unless index < skip }.compact
animals.map.with_index { |item, index| ( "#{index}:#{item}" ) unless index < skip }.compact
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby - Enumerable - each_with_index
You are viewing a single comment's thread. Return to all comments →
Solution 1 :
Solution 2 :
animals.map.with_index { |item, index| ( "#{index}:#{item}" ) unless index < skip }.compact