Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        8天前关闭。
                                                                                            
                
        
function FirstReverse(str) {
  str = str.split("");
  var res = str.reverse();
  str = res.replace(',', '');
  return str;
}

console.log(FirstReverse(readline()));

最佳答案

replace()是字符串原型的方法,由于res是不是字符串的数组,因此代码失败。

您应该加入反向字符数组,而不是使用replace()将其视为字符串,我想这就是您要尝试的操作。像这样:



function FirstReverse(str) {
  str = str.split("");
  var res = str.reverse();
  return res.join("");
}

var original = "ABCD";
var reversed = FirstReverse(original);

console.log(original);
console.log(reversed);

09-25 19:04