For why the code "passed this test actually" I have no answer - the test code must be defective.
What has been missed is that the string.replace
method returns a new string with a replacement made if a match for the first argument string was found, or an unmodified copy of the original string if no match was found. The string on which replace
is called remains unchanged.
So, while the str.replace()
calls may replace characters, the updated string returned by the call is not captured.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…