Tag: 柜台

计算数组中的更改

我想计算一下这个数组中”red”后跟”green” : [“red”, “orange”, “green”, “red”, “yellow”, “blue”, “green”] 如果它是另一种颜色,代码应该忽略它并继续到数组中的下一个项目。 event_type.each_slice(2) do |red, green| break unless green count = count + 1 end p “The count is #{count}” 步骤1: Look for red 第2步: IF not last item Compare with next item on array ELSE Go to Step 4 第3步: IF green, count = count + […]