我有一个初学者问题。我试图简单地将修改后的索引替换回原始字符串中以创建一个字符串数组。它们连续大写下一个元素中的下一个索引。这就是我所拥有的。谁能帮我看看我错过了什么?
def wave(str)
result = []
index = 0
while index < str.length
i = str[index]
if i == " "
index =+ 1
else
upper = i.upcase
val = str.rindex(upper) -1
result.push("#{str[0...val]}#{str[val..-1]}")
index += 1
end
end
result
end
我正在尝试从 ---> wave(hello) 获取: ["Hello", "hEllo", "heLlo", "helLo", "hellO"]
谢谢你。