爲什麼此代碼給這個輸入提供錯誤的輸出?迴文檢查紅寶石
def palindrome?(str)
str.delete('^a-zA-Z')
str.downcase
str == str.reverse
end
INPUT = "A man, a plan, a canal -- Panama"
OUTPUT = Failure/Error: palindrome?("A man, a plan, a canal -- Panama").should be_true, "Incorrect results for input: \"A man, a plan, a canal -- Panama\""
Incorrect results for input: "A man, a plan, a canal -- Panama"
# spec.rb:7:in `block (2 levels) in <top (required)>'
# ./lib/rspec_runner.rb:36:in `block in run_rspec'
# ./lib/rspec_runner.rb:32:in `run_rspec'
# ./lib/rspec_runner.rb:23:in `run'
# lib/graders/weighted_rspec_grader.rb:6:in `grade!'
# ./grade:31:in `<main>'
或者由於非修改版本返回你可以只把它們連一個新的字符串:'STR == str.delete( '[^ A-ZA-Z]')downcase.reverse'。 –
^this ....絕對是這個^ – Kyle
啊是的 - 我會說你的更習慣。 – hdgarrood