Answers for "each with index string ruby"

7

ruby each with index

colors = ['red', 'green', 'blue']
colors.each_with_index do |item, index|
	p "#{index}:#{item}" 
end

"0:red"
"1:green"
"2:blue"
Posted by: Guest on May-06-2020
0

ruby each char with index

length = sentence.length
sentence.each_char.with_index(1){|char, i|
  if i == length
    ...
  end
Posted by: Guest on August-17-2021

Browse Popular Code Answers by Language