Your code, but always capitalise the first letter, using each_with_index
to get the position in the array:
def titleize(string)
nocaps = ["the","and"]
string.split(" ").each_with_index.map { |word, i| i.positive? && nocaps.include?(word) ? word : word.capitalize }.join(" ")
end
titleize("the bridge over the river kwai")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…